Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Compete to become Power BI Data Viz World Champion! First round ends August 18th. Get started.

Reply
Raveeshlokanath
Frequent Visitor

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 let me know your thoughts.

 

 

1 ACCEPTED SOLUTION
rajendraongole1
Super User
Super User

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.

 

 





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!





View solution in original post

6 REPLIES 6
Raveeshlokanath
Frequent Visitor

Hi All,

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.

Anonymous
Not applicable

Hi @Raveeshlokanath ,

 

If your expected output looks like this:

2024-12-12_15-34-47.gif

You could try using field parameters, measure, and visual calculations to implement it.

vcgaomsft_0-1733989213304.png

vcgaomsft_1-1733989277643.png

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.

Anonymous
Not 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] ) )

vcgaomsft_1-1734327283689.png

vcgaomsft_2-1734327309399.png

 

 

Best Regards,
Gao

Community Support Team

Anonymous
Not applicable

Hi @Raveeshlokanath ,

 

At this time, this is not a viable option.
Bookmarks can be used to save sorted states, which may be a suitable alternative to consider if the number of dimensions is relatively small.

vcgaomsft_0-1733886057699.png

In the meantime, we kindly request that you submit this idea here to assist PowerBI in making improvements.
Welcome to Microsoft Fabric Ideas

 

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

rajendraongole1
Super User
Super User

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.

 

 





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!





Helpful resources

Announcements
August Power BI Update Carousel

Power BI Monthly Update - August 2025

Check out the August 2025 Power BI update to learn about new features.

August 2025 community update carousel

Fabric Community Update - August 2025

Find out what's new and trending in the Fabric community.

Top Solution Authors