Forum Discussion
Need to swap sorting dimension based on filter selection
- 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.
Hi Raveeshlokanath ,
If your expected output looks like this:
You could try using field parameters, measure, and visual calculations to implement it.
I have attached a pbix file for your reference.
Using visual calculations in Power BI Desktop - Power BI | Microsoft Learn
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
Thanks for your inputs, But my requirement is based on filter condition, i.e single select if made on slcier then I should use dimension A to sort else dimension B. How can I switch using dax.
- Anonymous1 year agoNot applicable
Hi Raveeshlokanath ,
Please try the method provided by rajendraongole1, for your ease of understanding I have attached a pbix file for reference.
DynamicSortValue = VAR SelectedSort = HASONEVALUE ( 'SortSelection'[SortOption] ) RETURN IF ( SelectedSort, MAX ( 'Table'[DimensionA] ), MAX ( 'Table'[DimensionB] ) )Best Regards,
Gao
Community Support Team