📝

Power Automateの注意点・使い方

2024/07/24に公開

この記事について

Power Automate クラウド版を使っている中で、注意した方が良いと思った点や、引っかかった点を中心まとめていきます。

Office 365についてくるクラウド版のPower Automateで自分の業務の自動化などをしています。
夜間にデータを出力し、Power BIを更新するのが主な使い道です。エラーが発生した時にSlackで通知が来るようにしたりもしています。

追加で課金が必要なサードパーティーツールなどは使っていません。

制約

あらかじめ把握しておいた方がよいPower Automateの制約をいくつかピックアップしました。
無理にPower Automateで自動化しようとすると、複雑になりすぎたり、逆に面倒くさいこともあります。

公式ドキュメント

Limits of automated, scheduled, and instant flows - Power Automate | Microsoft Learn

コネクターとアクション

コネクターやアクションは提供されているものから選ぶので、求めている操作ができなかったり、ひと工夫必要なこともあります。あらかじめ、使いたいアプリケーションのコネクターがあるか、やりたい操作のアクションが入っているか、確認しておくとよいです。

Apply to each array items: 5,000 for Low, 100,000 for all others

"Apply to each array"のアクションを使う際の制約です。
Excel Online (Business) コネクターの Add a row into a table アクションを使ってPower BIデータをExcel出力しようとして、制限に引っかかりました。
大量データをExcelに出力する際は、まずはCSVやJSON形式にしておいて、CSVをExcelに変換するOffice Scriptをつくり、"Run script"を実行して変換しています。

Apply to each array item
5,000 for Low, 100,000 for all others
This limit describes the highest number of array items that an "apply to each" loop can process.
To filter larger arrays, you can use the query action.

実行回数の制約 / Execution Limits

Power AutomateのFree Planでは、一日に実行できる回数に制限があります。
無料のPower Automate Free Planでは、一日に実行できるフロー回数は、合計で600回までです。制限は、実行するフローの数や、フローの実行時間によって異なるそうです。

トリガーの設定が、分単位になっていたりすると、すぐに制限に達してしまいます。
トリガー設定を変更し忘れていて、エラーが出たことがありました。新しいフローを作る際は気をつけましょう。

The Power Automate Free Plan is subject to limits on the number of times a flow can be executed in a day. Specifically, the number of flow executions that can be executed in a day with the Power Automate Free Plan is limited to a total of 600. These limitations vary depending on the number and duration of the flows being executed, so adjustments should be made accordingly.

50MBの制限

URLからOneDriveにデータをダウンロードする場合、50MBまでの制限があります。

どうしても、データ量大きいものをダウンロードしたい場合は、一旦Power BIで読み込み、必要なデータだけをPower BI経由でダウンロードしています。

基本の使い方

個人的に一番よく使うスケジュール実行フローの作り方です。

  1. New flow
  2. Automated cloud flow
  3. フローの名前を入力 (後で変更できるので適当でOK)
  4. Select a trigger (スケジュール実行ができる Recurrence (繰り返し) を選ぶことが多いです。)
  5. 好きなアクションを追加していく

スケジュール実行時の注意点

TriggerでRecurrenceを選び、下記のように設定したとします。
Frequency: Day
At these hours: 14
At these minutes: (空白)

この場合、14時きっかりではなく、14時台の任意のタイミングに実行されてしまいます。
14時ちょうどに実行を開始したい場合、minutesまで設定します。

Power BI

Power BI - Connectors | Microsoft Learn

Power BIからデータを取得する

  1. コネクター: Power BI > アクション: Run a query against dataset を追加
  2. dataset選択
  3. DAX Queryを入力する

DAX Query の取得方法
方法1

  1. Power BI Desktopで取得したい値を含む表を作成
  2. Performance Analyzer > Record > Refresh > Stop > Copy Query

方法2
Power BI Web > dataset > Tables > 出力したい行を選択 > Show query

Apply to each で指定した列の値を取得する

  1. Apply to each アクションを追加
  2. Select an output from previous steps で Run a query against dataset の First table rows を選択
  3. item()?['table[column_name]'] と入力すると、指定列の値が取得できる

例) item()?[‘data[url]’]

Change column names when exporting data from Power BI | Run a query against a dataset - YouTube

日付のフォーマットを変更する

formatDateTime(item()?['data[date]'],'[フォーマットを指定]')
例) formatDateTime(item()?['data[date]'],'yyyy-MM-dd HH:mm:ss')
Power Automate 「formatDateTime」関数 | 誰でもできる業務改善講座

Discussion