top of page

You are learning Power Query in MS Excel

How to filter data based on specific criteria in Power Query?

There are two main ways to filter data based on specific criteria in Power Query:

1. Using the Filter Rows Dialog:

* Select the column you want to filter by.
* Click the down arrow next to the column header.
* Choose "Filter rows" from the dropdown menu.

This opens the Filter Rows dialog box. Here you can choose different filtering options based on data types:

* Text Filters: Options like "Equals", "Contains", "Begins with", "Ends with", etc.
* Number Filters: Options like "Equals", "Does Not Equal", "Greater Than", "Less Than", "Between", etc.
* Date/Time Filters: Options based on specific dates, relative periods (e.g., Last Week), or date parts (e.g., Year, Month).

You can also combine multiple filters using "AND" or "OR" logic by clicking the appropriate buttons in the dialog.

2. Using M Language (Formula Editor):

Power Query uses a formula language called M. You can achieve more complex filtering logic by writing M formulas in the formula editor. Here's a basic example:

```
let
dataTable = yourDataTable,
filteredData = Table.SelectRows(dataTable, row => row["ColumnName"] = "Specific Value")
in
filteredData
```

This code snippet:

1. Defines a variable `dataTable` that holds your data table.
2. Uses the `Table.SelectRows` function to filter the table.
3. The function takes two arguments: the table to filter and a formula that evaluates each row.
4. The formula `row["ColumnName"] = "Specific Value"` checks if the value in the "ColumnName" column matches "Specific Value".
5. Only rows where the condition is true are included in the filtered data (`filteredData`).

Remember:

* Replace "ColumnName" with the actual column name you want to filter by.
* Adjust the comparison operator (`=`) and value based on your specific criteria.
* You can write more complex M formulas for advanced filtering logic.

For more information and examples, refer to the official Microsoft documentation on filtering in Power Query: [https://support.microsoft.com/en-us/office/filter-data-power-query-b5610630-f5bf-4ba4-9217-a628f9b89353](https://support.microsoft.com/en-us/office/filter-data-power-query-b5610630-f5bf-4ba4-9217-a628f9b89353)

bottom of page