Forum Discussion

andhiii102030's avatar
andhiii102030
Frequent Visitor
1 year ago
Solved

Sort by column within sub groups

Hi,   i have a special problem and no good solution right now for this case. I have KPI which are group by categories.  Costs: is, calculated, should profit: is, calculated  No i try to so...
  • Anonymous's avatar
    Anonymous
    1 year ago

    Hi andhiii102030 ,

    What problem do you encounter here? I think concatenating strings is a valid solution.

    Some tricks like to add space after "is" is not a solution to create unique values in the table: "is " or "is  "

    Here are my steps:

    1.Creating an index column after grouping in Power Query(The index column is not used for the final sort)

    2.Use the following DAX expression to create  columns

    Column = [Count.Sort column] & REPT(" ",[Index])
    Column 2 = SWITCH(
        TRUE(),
        [Count.KPI] = "costs" && [Count.Sort column] = "is",1,
        [Count.KPI] = "costs" && [Count.Sort column] = "calculated",2,
        [Count.KPI] = "costs" && [Count.Sort column] = "should",3,
        [Count.KPI] = "profit" && [Count.Sort column] = "is",2,
        [Count.KPI] = "profit" && [Count.Sort column] = "calculated",1
    )

    3.Final output

     

    Best Regards,
    Wenbin Zhou