Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
Anonymous
Not applicable

Conditional Filtering based on another column value

I have some data that has bad values and I am trying to filter out values not in a range. The issue I am running into is that ther are more than 1 range the values can be in depending on the product. I tried writing an if statement that will filter the column but I keep running into errors.

First I get this error:

"Expression.SyntaxError: Token Else expected."

Then after adding an 'else' I get:

"Expression.SyntaxError: Token Literal expected." or "Expression.Error: We cannot convert a value of type Function to type Logical."

This is what I have so far:

 

 

= Table.SelectRows(#"Changed Type1", each if [Spec Denier] = 1385 or 1411 or 1426 then each [Denier] = null or ([Denier] >= 1300 and [Denier] <= 1500) else if [Spec Denier] = 1700 then each [Denier] = null or ([Denier] >= 1600 and [Denier] <= 1800))

 

 

 I have tried removing the 'or' in the if statement and adding an 'else' at the end. All I want to do is keep the blank data and make sure that the data is in the range for that product.

4 REPLIES 4
Anonymous
Not applicable

The data that I have is manually input and sometimes there are typos. I want to filter them in a range based on the denier it is supposed to be (ie. 1411 or 1700). Here is example data. The quality column shows if the data should be kept or filtered out.

DateMachine #Denierquality
12/4/2022  521420good
12/4/2022521435good
12/4/2022521685BAD
12/4/2022521413good
12/4/2022521395good
12/4/2022521435good
12/4/2022521437good
12/4/2022521402good
12/4/2022521444good
12/4/2022521285BAD
12/4/2022521444good
12/4/2022521395good
12/4/2022521435good
12/4/2022521436good
12/4/2022521416good
12/4/2022521450good
12/5/2022611682good
12/5/2022611411BAD
12/5/2022611721good
12/5/2022611683good
12/5/2022611742good
12/5/2022611751good
12/5/2022611680good
12/5/2022611727good
12/5/2022611712good
12/5/2022611729good
12/5/20226111700BAD
12/5/2022611699good
12/5/2022611697good

Hi @Anonymous 

 

Which rows do you want to keep?

 

If you want to keep all quality Good rows, you can click the down icon on "quality" column header and select "good" value. 

vjingzhang_0-1672969064851.png

 

If you want to add more filter conditions, you can double click the "Filtered Rows" step in "Applied Steps" pane. This will open a "Filter Rows" window. Switch to "Advanced" option, then you are able to add multiple conditions. After clicking "ok", it will generate an M statement for you automatically. 

vjingzhang_1-1672969868045.png

 

To filter several ranges based on different machines, you can try something like below.

= Table.SelectRows(#"Changed Type", each ([#"Machine #"] = 52 and ([Denier] >=1400 and [Denier] <=1500)) or ([#"Machine #"] = 61 and ([Denier] =11700 or [Denier] <=1500)))

vjingzhang_2-1672970708372.png

 

Hope above examples help. If it doesn't help, can you give a detailed example that which range you want to keep or filter out based on the current data?

 

Best Regards,
Community Support Team _ Jing
If this post helps, please Accept it as Solution to help other members find it. Highly appreciate your Kudos!

v-jingzhang
Community Support
Community Support

Hi @Anonymous 

 

The syntax of your IF statement is not correct, so you have those errors. Please share some sample data to help us understand your expected result better. You can use natural language or examples to explain the logic for filtering. At present we have difficulty understanding your requirement from the incorrect IF statement. 

 

Best Regards,
Community Support Team _ Jing

Mahesh0016
Super User
Super User

Can you share sample data and sample output in table format? Or a sample pbix after removing sensitive data.

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

December 2025 Power BI Update Carousel

Power BI Monthly Update - December 2025

Check out the December 2025 Power BI Holiday Recap!

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.