Forum Discussion

Raveeshlokanath's avatar
Raveeshlokanath
Frequent Visitor
1 year ago
Solved

Need to swap sorting dimension based on filter selection

Hello All,   I need to swap sorting dimension, based on slicer selection in DAX, i.e in the drop down if single selection is made then need to sort the visual with Dimension A else B.   please le...
  • rajendraongole1's avatar
    1 year ago

    Hi Raveeshlokanath - Power BI visuals don't directly support sorting by multiple columns conditionally based on slicer input.

     

    Create a disconnected table (let’s call it SortSelection) with two values: Dimension A and Dimension B.

    SortSelection =
    DATATABLE(
    "SortOption", STRING,
    {
    {"Dimension A"},
    {"Dimension B"}
    }
    )

     

    Create a measure to dynamically calculate the sort value based on the slicer selection

     

    DynamicSortValue =
    VAR SelectedSort = SELECTEDVALUE(SortSelection[SortOption], "Dimension A")
    RETURN
    SWITCH(
    SelectedSort,
    "Dimension A", MAX('YourTable'[DimensionA]),
    "Dimension B", MAX('YourTable'[DimensionB]),
    BLANK()
    )

     

    Apply the Sorting Measure in Your Visual:

    Add your DynamicSortValue measure to your visual.
    Sort the visual by DynamicSortValue.

     

    Try the above approach. please check.