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
flow12345
New Member

How to filter conditional If in power query

Hi i have a column in power query where the data is my sheet name and the names are ABC 2023 and ABC 2023 B2. I want to filter it such that if my source does not have a ABC 2023 B2, it will filter and return only ABC 2023. But if there is a ABC 2023 B2 worksheet then it will give me the one with B2 instead. 

 

i tried using text.contains but my formula is not working

Here's a snapshot of what i meant

flow12345_0-1693451528194.png

 

Any help is appreciated!

1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi @flow12345 ,

My idea is to filter for rows ending in "B2", otherwise filter for shortest character lengths:

vcgaomsft_0-1693817591058.png

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WcnRyVjAyMDJWitVBcBScDJViYwE=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Custom.Name = _t]),
    Custom1 = if Table.RowCount(Table.SelectRows(Source, each Text.EndsWith([Custom.Name], "B2"))) < 1 then Table.SelectRows(Source, each Text.Length([Custom.Name]) =  List.Min(List.Transform(Source[Custom.Name],each Text.Length(_))) ) else Table.SelectRows(Source, each Text.EndsWith([Custom.Name], "B2"))
in
    Custom1

Best Regards,
Gao

Community Support Team

 

If there is any post helps, then please consider Accept it as the solution  to help the other members find it more quickly. If I misunderstand your needs or you still have problems on it, please feel free to let us know. Thanks a lot!

How to get your questions answered quickly --  How to provide sample data in the Power BI Forum

View solution in original post

2 REPLIES 2
Anonymous
Not applicable

Hi @flow12345 ,

My idea is to filter for rows ending in "B2", otherwise filter for shortest character lengths:

vcgaomsft_0-1693817591058.png

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WcnRyVjAyMDJWitVBcBScDJViYwE=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Custom.Name = _t]),
    Custom1 = if Table.RowCount(Table.SelectRows(Source, each Text.EndsWith([Custom.Name], "B2"))) < 1 then Table.SelectRows(Source, each Text.Length([Custom.Name]) =  List.Min(List.Transform(Source[Custom.Name],each Text.Length(_))) ) else Table.SelectRows(Source, each Text.EndsWith([Custom.Name], "B2"))
in
    Custom1

Best Regards,
Gao

Community Support Team

 

If there is any post helps, then please consider Accept it as the solution  to help the other members find it more quickly. If I misunderstand your needs or you still have problems on it, please feel free to let us know. Thanks a lot!

How to get your questions answered quickly --  How to provide sample data in the Power BI Forum

Legend_11
Resolver I
Resolver I

Try Adding conditonal column in power query

Legend_11_0-1693457354886.png

 

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.