SlideShare uma empresa Scribd logo
1 de 36
Baixar para ler offline
POWER PLATFORM WINTER 2019 @MICROSOFT JAPAN
Power Apps キャンバスアプリ ハンズオン
カレンダースクリーンの応用 – 年間カレンダーを作ってみよう!
PowerApps University Student ID Card
今日のお題
 Power Appsのキャンバスアプリで利用可能な画面テンプレート「カレンダー」から、年間カレンダーを作成!
何がうれしいの??
 画面テンプレートはPowerAppsのテクニックの塊!これを紐解くのがステップアップの最短ルート
ギャラリー、ラベル、ドロップダウンなどの
コントロールがいっぱい
ギャラリーには比較的高度な数式が!
何がうれしいの??
 Power Appsはデータ操作ができてからが本番!今回もデータ操作が盛りだくさん!
1か月分のカレンダーをx12
→データテーブル化
何がうれしいの??
 Power Appsはデータ操作ができてからが本番!今回もデータ操作が盛りだくさん!
1か月分のカレンダーをx12
→データテーブル化
Power Appsのデータ操作に
とにかく慣れよう!!
本日の流れ
標準のカレンダースクリーンの解説 (10分)
データ準備 (10分)
作成(20分)
枠ぐみ 10分
エラー処理 10分
※予定の表示は参考資料でやってみてください!
カレンダースクリーンの解析
まずは追加してみよう!
 今回は電話レイアウトで進めます
 新規アプリを作成し、「カレンダー」画面を追加しましょう
電話レイアウトでアプリを新規作成 「新しい画面」から「カレンダー」を追加
カレンダーを表示してみよう
 ▶再生ボタンを押して、動きを確認
今日の日付をクリック
カレンダーが表示されるので×で閉じる
コントロールを確認しよう
 ほとんどギャラリーコントロール
コントロールを確認しよう
 ほとんどギャラリーコントロール
??ギャラリーコントロールって?
いわゆる「一覧」を表示するコントロール
主に使うのは Items プロパティとWrapCount
データソースから取得したデータや、ローカルのテーブル
(Collection) を表示するために利用する
変数を確認しよう!
 グローバル変数としてたくさんの変数が定義されている
これらの日付関連の変数が重要!
カレンダーの本体 – MONTHDAYGALLERY
 MonthDayGalleryが本体。これがちょっと大変
~MonthDayGalleryでの処理~
1. 表示する月の初日を求める
2. 表示する月の最初の週の日曜日の日付を求める
3. 表示する月の最終日を求める
4. 元のテーブルの値と、表示している実際の日付の差分
が10より小さければ塗りつぶしなし。それ以外の日付で
はグレーに塗りつぶす
ここで大事な関数
 カレンダーは基本的に日付の足し算でできている
DateAdd
+ 1日
+ 2日
+ 34日
カレンダー表示上の初日 (各月の1日ではない)に
+1,+2….+41と日数を足すことでカレンダーを構成
ここで大事な関数
 カレンダーは基本的に日付の足し算でできている
DateAdd
+ 1日
+ 2日
+ 34日
DateAdd(表示初日, ThisItem.Value, Days)
[0,1,2…,41]の各数値
カレンダー表示上の初日 (各月の1日ではない)に
+1,+2….+41と日数を足すことでカレンダーを構成
ここで大事な変数
 _firstDayInViewさえ求められれば、あとは足し算するだけ
表示上の初日 _firstDayInView
カレンダースクリーンまとめ
 カレンダーは 0~41の数字から構成された、MonthDayGalleryがメイン
 カレンダー上の日付を求めるためには表示上の初日(カレンダーの左上の日付)が重要
 各アイテムの表示日付は、DateAdd関数を利用
DateAdd(表示上の初日, 各アイテムの数値, Days)
 このあと使う変数
 _firstDayOfMonth
 _firstDayInView
 _lastDayOfMonth
データの準備
年間カレンダーにはどんなデータが必要か?
 1か月分のカレンダー表示に必要なのは3つの変数
_firstDayOfMonth : 月の初日
_firstDayInView : 表示上の初日
_lastDayOfMonth : 月の最終日
年間カレンダーにはどんなデータが必要か?
 1か月分のカレンダー表示に必要なのは 3つの変数 の 12セット が必要
1月用 2月用 12月用
・・・
3月用
年間カレンダーにはどんなデータが必要か?
 1か月分のカレンダー表示に必要なのは 3つの変数 の 12セット が必要
1月用 2月用 12月用
・・・
3月用
3列 12行の テーブル (Collection) を作る
どうやってデータを作るか
 すべての起点は firstDayOfMonth. ほかの2つはそこから計算される
Set(_firstDayInView,DateAdd(_firstDayOfMonth, -(Weekday(_firstDayOfMonth) - 1), Days));
Set(_lastDayOfMonth,DateAdd(DateAdd(_firstDayOfMonth,1, Months), -1, Days));
どうやってデータを作るか
 すべての起点は firstDayOfMonth. ほかの2つはそこから計算される
Set(_firstDayInView,DateAdd(_firstDayOfMonth, -(Weekday(_firstDayOfMonth) - 1), Days));
Set(_lastDayOfMonth,DateAdd(DateAdd(_firstDayOfMonth,1, Months), -1, Days));
どうやってデータを作るか
 以下のステップでCollectionを作成
① 月の初日だけを含むCollection作成
② AddColumns関数で2つの計算列を追加
ここで大事な関数
 AddColumns関数はデータに列を追加する関数
AddColumns( 元のデータ, 追加する列名, 計算式 )
AddColumns
例えば、月の最終日は・・・ 「月の初日」の「1月後」 の「1日前」
AddColumns(元のデータ, “_lastDayOfMonth”,
DateAdd( DateAdd(_firstDayOfMonth, 1, Months) , -1 , Days) )
1か月後 1日前
データを作成しよう
 最初につくったアプリのScreen1に移動し、ボタンを追加
 ボタンのOnSelectプロパティに以下の関数をコピペ
//初期の表示年は今年
UpdateContext({_selectedYear:Year(Today())});
//まず2019/1/1~2019/12/1まで、12か月の初日を収めた仮のCollectionを作成
Clear(colTmp);
ForAll([1,2,3,4,5,6,7,8,9,10,11,12],
Collect(colTmp,{_firstDayOfMonth:Date(_selectedYear,Value,1)})
);
//カレンダーの表示に必要な_firstDayInViewと_lastDayOfMonthを列としてCollectionに追加
ClearCollect(colCalendar,
AddColumns(colTmp,
//それぞれの定義はテンプレートと同一
"_firstDayInView",DateAdd(_firstDayOfMonth,-(Weekday(_firstDayOfMonth) - 2 + 1), Days),
"_lastDayOfMonth",DateAdd(DateAdd(_firstDayOfMonth,1, Months), -1, Days)
)
);
//あとのためカレンダー表示・非表示用の変数を用意
UpdateContext({_calendarVisible:true})
データを確認してみる
 データテーブルを追加し、Itemsプロパティに先ほどのボタンで作成したCollectionを設定
 [フィールド]>[フィールドの編集]で、すべての列を選択
必要なデータの準備は完了
年間カレンダー作成
年間カレンダーの作成
 データがそろったので、カレンダーの表示を作っていく
 単月のカレンダーはMonthDayGallery というGalleryコントロールで表現されていたので、これを12倍に
➡ Galleyの中に単月のカレンダーを挿入する
空のギャラリーの中にMonthDayGalleryを
入れ子にする
x12
Gallery化
手順を伝えるのは難しいので動画で。。。
エラーの処理
 いくつかエラーが出ているので、修正します。
lblMonthSelected1.Colorでエラー
➡Color.Blackに変更
Circle1_1.Visibleでエラー
➡コントロールごと消す
ほぼ完成!!
あとは・・・
• 月の表示がないので追加
• 月の間にセパレータ(境界がないので追加)
• 色味の変更
まとめ
まとめ
 カレンダースクリーンは以下の3つで構成されている
 MonthDayGallery : 日付部分
 WeekdayGallery : 曜日表示
 CalendarEventGallery : Outlook予定表から取得されるイベント表示 (今回は割愛)
 MonthDayGallery (カレンダーの日付本体)は3つの重要な変数で構成
 _firstDayOfMonth : 月の初日
 _firstDayInView : 表示上の初日
 _lastDayOfMonth : 月の最終日
 同じような構造を繰り返しする場合には
変数➡テーブル 単一コントロール➡ギャラリー が有効
 重要な関数は以下
 DateAdd : 日付の足し算/引き算
 AddColumns : あるデータに列追加 計算列などを表示に使う際に有効
ご参加ありがとうございました

Mais conteúdo relacionado

Destaque

How Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthHow Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental Health
ThinkNow
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie Insights
Kurio // The Social Media Age(ncy)
 

Destaque (20)

2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot
 
Everything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPTEverything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPT
 
Product Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsProduct Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage Engineerings
 
How Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthHow Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental Health
 
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfAI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
 
Skeleton Culture Code
Skeleton Culture CodeSkeleton Culture Code
Skeleton Culture Code
 
PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie Insights
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search Intent
 
How to have difficult conversations
How to have difficult conversations How to have difficult conversations
How to have difficult conversations
 
Introduction to Data Science
Introduction to Data ScienceIntroduction to Data Science
Introduction to Data Science
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best Practices
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project management
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
 

Power platform Day Winter 19 -PowerApps