Advanced | Flow of the Week: Filtering Data with OData - Microsoft Power Platform Blog (2024)

OData (Open Data Protocol) is an OASIS standard that establishes best practices for designing RESTful APIs. One of the capabilities of OData is providing the ability to filter data using a standardized method across RESTful APIs, regardless if they are vendor provided or custom developed. Since Microsoft Flow’s connectors are built-upon RESTful APIs, many of our connectors support the ability to filter datasets server-side using OData. Some of the benefits of using OData include reducing the amount of data you are bringing into your flow, thus reducing the need to loop through a record set to find values of interest.

In this blog post we are going to explore some popular OData filter expressions that you can use with some of our most popular connectors including SQL Server, Dynamics 365 and SharePoint Online.

Scenario #1: Get Rows from SQL Server and filter on Customer Name

We have the following Azure SQL database with a table that contains many work orders. From Microsoft Flow, we want to return only rows where the Customer Name is equal to ‘Contoso’

Advanced | Flow of the Week: Filtering Data with OData - Microsoft Power Platform Blog (1)

Inside of Microsoft Flow, we can add a SQL Server – Get Rows action. After providing a​Table namewe also have the ability to provide a​Filter Query​. Inside this textbox we will provide a statement of CustomerName eq ‘Contoso’. The breakdown of this syntax is we need to provide the name of the field in the source system (i.e. SQL Server), followed by an operator. In this case we want to use = which is represented as eq in OData. Don’t use the = symbol otherwise you will get a runtime error. Lastly, we need to provide a value that we want to filter on. In this case we want to filter onContoso.​ Since it is a string, we need to wrap it in single quotes ‘ ‘.

Advanced | Flow of the Week: Filtering Data with OData - Microsoft Power Platform Blog (2)

For the purposes of this blog post, we will wrap the results in HTML and send them via Office 365 Outlook connector so we can verify our results.

Advanced | Flow of the Week: Filtering Data with OData - Microsoft Power Platform Blog (3)

After the flow executes, our we will see our results rendered successfully and only records with a Customer Name of Contoso are displayed.

Advanced | Flow of the Week: Filtering Data with OData - Microsoft Power Platform Blog (4)

Scenario #2: Get Rows from SQL Server and filter on date

In this scenario we want to filter out older records and only retrieve records that have a Work Order Create Date that is less than 30 days old. To accomplish this we will also use a flow expression that will calculate the date, 30 days ago. We will then look for any records that have a Work Order Create Date that is greater than this date. The complete expression is: WorkOrderCreatedTime gtaddDays(utcnow(‘yyyy-MM-ddTHH:mm:ssZ’),-30). In this scenario, WorkOrderCreatedTime is our source field, gt​represents our ‘greater than’ operator and addDays(utcnow(‘yyyy-MM-ddTHH:mm:ssZ’),-30) will calculate a date of 30 days prior.

Advanced | Flow of the Week: Filtering Data with OData - Microsoft Power Platform Blog (5)

The results only include records that are less than 30 days old.

Advanced | Flow of the Week: Filtering Data with OData - Microsoft Power Platform Blog (6)

Scenario #3: List Records from Dynamics 365 using an AND clause

We will now move onto the Dynamics 365 connector where we can also use OData to filter out records. In this case we want to want to retrieve only records where the Account Name is Contoso Hospital AND theCityisPhoenix​.

Advanced | Flow of the Week: Filtering Data with OData - Microsoft Power Platform Blog (7)

​To accomplish this we will use anAND​ clause that will let us join two statements. The first being our (Account) name being equal to ‘Contoso Hospital‘ and secondly, our address1_city being equal to ‘Phoenix’. Our complete statement is name eq ‘Contoso Hospital’ and address1_city eq ‘Phoenix’.

Advanced | Flow of the Week: Filtering Data with OData - Microsoft Power Platform Blog (8)

When we execute our flow, we will see results only related to the Contoso Hospital in Phoenix.

Advanced | Flow of the Week: Filtering Data with OData - Microsoft Power Platform Blog (9)

Scenario #4: List Records from SharePoint Online that Starts With

In our final scenario, we are going to filter records from a custom SharePoint list. In this particular example, we have 4 records within a SharePoint List and we want to filter on all sites that start with the word ‘Contoso’​.

Advanced | Flow of the Week: Filtering Data with OData - Microsoft Power Platform Blog (10)

From a flow perspective, we will include the following OData query within our SharePoint action: startswith(Title,’Contoso’) whereTitle​is the name of the column that we want to filter on and​Contoso​ is the value we want to the column to start with.

Advanced | Flow of the Week: Filtering Data with OData - Microsoft Power Platform Blog (11)

​When our flow runs, we will discover that only the Site Names that beginthe wordContosoare included in our results.

Advanced | Flow of the Week: Filtering Data with OData - Microsoft Power Platform Blog (12)

Conclusion

​In this blog post we covered 4 different OData queries across 3 different connectors including SQL Server, Dynamics 365 and SharePoint Online. While the syntax is a little different than what you are used to when using T-SQL, the power available to you unlocks new ways to filter your data in Microsoft Flow. Using OData to filter at the data source will reduce execution times as it reduces the need to loop through data sets in order to find specific records. So not only is this more efficient by sending smaller messages around, but it will also allow your flows to run faster.

For more examples of OData filter expressions, please check out the following Microsoft page.

Advanced | Flow of the Week: Filtering Data with OData - Microsoft Power Platform Blog (13)

Kent Weare

See more articles from this author

Advanced | Flow of the Week: Filtering Data with OData - Microsoft Power Platform Blog (2024)
Top Articles
Latest Posts
Article information

Author: Dean Jakubowski Ret

Last Updated:

Views: 5990

Rating: 5 / 5 (70 voted)

Reviews: 85% of readers found this page helpful

Author information

Name: Dean Jakubowski Ret

Birthday: 1996-05-10

Address: Apt. 425 4346 Santiago Islands, Shariside, AK 38830-1874

Phone: +96313309894162

Job: Legacy Sales Designer

Hobby: Baseball, Wood carving, Candle making, Jigsaw puzzles, Lacemaking, Parkour, Drawing

Introduction: My name is Dean Jakubowski Ret, I am a enthusiastic, friendly, homely, handsome, zealous, brainy, elegant person who loves writing and wants to share my knowledge and understanding with you.