Forum Discussion

flow12345's avatar
flow12345
New Member
3 years ago
Solved

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 an...
  • Anonymous's avatar
    Anonymous
    3 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
        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