Forum Discussion
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
Any help is appreciated!
- Anonymous2 years ago
Hi flow12345 ,
My idea is to filter for rows ending in "B2", otherwise filter for shortest character lengths: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 Custom1Best Regards,
Gao
Community Support TeamIf 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
2 Replies
- Legend_11Resolver I
Try Adding conditonal column in power query
- AnonymousNot applicable
Hi flow12345 ,
My idea is to filter for rows ending in "B2", otherwise filter for shortest character lengths: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 Custom1Best Regards,
Gao
Community Support TeamIf 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