Powerautomate フィルタークエリ はい/いいえ

Does your Power Automate flow need to filter only flagged documents using Yes/No (boolean) column and ignore the rest?

Did you try all possible combinations in the filter query …column eq true, …column eq ‘true’, …equals(column, ‘true’)… but none of them works?


While SharePoint is displaying the values as ‘Yes’ or ‘No’ to the users, and as ‘true’ or ‘false’ on the background, to make a working filter on Yes/No (boolean) column in Power Automate you have to use numbers, Yes = 1, No = 0.

That means you must define the filter in the following format.

YesNo_column eq/ne 1
or
YesNo_column eq/ne 0
Powerautomate フィルタークエリ はい/いいえ

Before I found this solution I had a lot of flows where the filtering was done after the Get items action. But moving the filter into the Get items action itself instead of using IF condition did simplify the flow, made it much faster and also much easier to debug when needed.

If also your flows have conditions like the one below, you too should consider optimizing them.

Powerautomate フィルタークエリ はい/いいえ

Powerautomate フィルタークエリ はい/いいえ
Power Automate

2022.03.13 2021.01.21

Power Automateの「複数の項目の取得」アクションでフィルタークエリを設定するとき、ODataフィルタークエリで指定する必要がある。

このODATAクエリってのが意外と情報がないので、使い方をまとめてみた。

ODATAとは

ODataとはOpen Data Protocolの略で、HTTPを使ってやり取りするときに使うプロトコルのこと。

ODataとはでググるとわかりやすい解説がたくさん出てくるので、興味のある方はぜひ。

フィルターの仕様

ODataを使ったフィルターの書き方は、↓の公式が一番詳しいと思われ。

※わかりやすいかはまた別w

実際にフィルターをかけてみる

ということで、公式をみるよりやってみた方が早そうなので、サンプルリストとPower Automateを作って実際にやってみる。

今回使用するリストはこんな感じ。

Powerautomate フィルタークエリ はい/いいえ

そして、こんなPower Automateを準備して、順にフィルターをかけていく。

Powerautomate フィルタークエリ はい/いいえ

最後のApply to eachは、フィルターがうまく動作しているかを見るためだけのものなので気にせずに。

比較演算子

まずは比較演算子から。

等しい:eq

リストからNumber列が3のアイテムを持ってきたい場合は、こんな感じ。

Powerautomate フィルタークエリ はい/いいえ

すると結果はこんな感じで、Number列が3のやつだけ持ってこれている。

Powerautomate フィルタークエリ はい/いいえ

等しくない:ne

逆にリストからTitle列がccc以外のアイテムを持ってきたい場合は、こんな感じ。
数字比較のときはあってもなくてもよい「”」だけど、文字列比較の時は忘れないように

Powerautomate フィルタークエリ はい/いいえ

結果はこんな感じ。4つアイテムが取れてきて、タイトル「ccc」のやつだけフィルターされている。

Powerautomate フィルタークエリ はい/いいえ

より大きい:gt

Number列が3より大きいものが欲しいときはこんな感じ。

Powerautomate フィルタークエリ はい/いいえ

結果はこんな感じで、2つだけアイテムが取得できる。

Powerautomate フィルタークエリ はい/いいえ

より小さい:lt

3より小さいものが欲しいときはこんな感じ。

Powerautomate フィルタークエリ はい/いいえ

結果は、Number列が1と2のアイテムだけ取得できる。

Powerautomate フィルタークエリ はい/いいえ

以上:ge

続いてNumber列が3以上のアイテムを取得。

Powerautomate フィルタークエリ はい/いいえ

結果はこんな感じで成功!

Powerautomate フィルタークエリ はい/いいえ

以下le

最後はNumber列が3以下のアイテムを取得。

Powerautomate フィルタークエリ はい/いいえ

結果はこんな感じで成功!

Powerautomate フィルタークエリ はい/いいえ

論理演算

条件が複数ある場合は、論理演算子で結び付けてあげる。

and

Number列が3以上かつTitle列が「ddd」以外のやつだけ欲しい場合は、こんな感じ。

Powerautomate フィルタークエリ はい/いいえ

とれたのは「ccc」と「eee」なので成功!

Powerautomate フィルタークエリ はい/いいえ

or

Number列が4より大きい、またはTitle列が「aaa」のやつだけ欲しい場合は、こんな感じ。

Powerautomate フィルタークエリ はい/いいえ

結果はこんな感じで、Numberが5のアイテムと、Titleがaaaのやつが取れているので成功!

Powerautomate フィルタークエリ はい/いいえ

かっこ()

フィルタークエリにはかっこ()も使える。

例えば、(Number列が1または4)かつ(Titleが「aaa」または「ccc」のやつ)みたいな指定はこんな感じになる。

Powerautomate フィルタークエリ はい/いいえ

結果はこんな感じで、この条件に当てはまるアイテムは1個だけなので成功!

Powerautomate フィルタークエリ はい/いいえ

補足:SharePointリストの列を日本語で作った場合

もしSharePointの列を日本語で作ってしまった場合は、Odataクエリに直すには少し工夫が必要。

まずSharePointのリストの設定へとアクセスして

Powerautomate フィルタークエリ はい/いいえ

日本語で作った列をクリックする

Powerautomate フィルタークエリ はい/いいえ

すると、その列のページへと遷移するので、アドレスバーのFieldIDの中身をコピーする。
この値の頭に「OData_」を付けてあげたやつが、その列名になる。

Powerautomate フィルタークエリ はい/いいえ

今回のサンプルリストの「数字」列の値でフィルターをかけたいときは、こんな感じ。

Powerautomate フィルタークエリ はい/いいえ

「数字」列が8のやつだけ持ってきているので、結果はこんな感じになる。

Powerautomate フィルタークエリ はい/いいえ

関連記事