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

Don't miss out! 2025 Microsoft Fabric Community Conference, March 31 - April 2, Las Vegas, Nevada. Use code MSCUST for a $150 discount. Prices go up February 11th. Register now.

Reply
RamyaKrishna_61
Helper II
Helper II

Field Parameters_ Sorting the visual based on measure and in ascending order issue in bar chart

Hi All,
I have created field parameters and using them in my clustered bar chart for both x-axis and y-axis. On y axis I have taken dimensions related field parameters and on x-axis I have taken measures related field parameters. 

My requirement here to sort my visual based on one measure and in ascending order. But when I change the options and go to other options(changing the parameters related to visual) then it is getting reset. 

I have seen that the similar issue is posted in 2022.

Can we have solution for this?

@lbendlin 

1 ACCEPTED SOLUTION
speedramps
Super User
Super User

When you create field parameter it creates a table with hidden columns

You can view these in the view hidden menu

 

speedramps_0-1737383136156.png

X measure  parameters = {
    ("Quantity", NAMEOF('Dax'[Quantity]), 0),
    ("Value", NAMEOF('Dax'[Value]), 1),
    ("Freight", NAMEOF('Dax'[Freight]), 2)
}

 

The "order" column controls what sequence the field parameters appear in the slicers and headers. 

We can capture and use this field to contol the sort sequence of your clustered bar chart.

 

Create measure.

Sorter = 
VAR Xoption = SELECTEDVALUE('X measure  parameters'[X measure  parameters Order])
RETURN
SWITCH(Xoption,
    0,[Quantity],
    1,[Value],
    2, [Freight]
)

The SELECTEDVALUE gets the  selected "order" for the measure you picked on the slicer.

The SWITCH then gets the equivalent measure value

 

Add the Sorter to your your clustered bar chart as tootltip.

The click on three dots [...], Sort axis, Sorter, Descending

speedramps_1-1737383720525.png

 

Change the measure to handle multiple selections if required, so it slected you prefered measure sort sequence.

 

Please click [accept solution] and thumbs up buttons to show your appreciation.

 

 

View solution in original post

4 REPLIES 4
speedramps
Super User
Super User

When you create field parameter it creates a table with hidden columns

You can view these in the view hidden menu

 

speedramps_0-1737383136156.png

X measure  parameters = {
    ("Quantity", NAMEOF('Dax'[Quantity]), 0),
    ("Value", NAMEOF('Dax'[Value]), 1),
    ("Freight", NAMEOF('Dax'[Freight]), 2)
}

 

The "order" column controls what sequence the field parameters appear in the slicers and headers. 

We can capture and use this field to contol the sort sequence of your clustered bar chart.

 

Create measure.

Sorter = 
VAR Xoption = SELECTEDVALUE('X measure  parameters'[X measure  parameters Order])
RETURN
SWITCH(Xoption,
    0,[Quantity],
    1,[Value],
    2, [Freight]
)

The SELECTEDVALUE gets the  selected "order" for the measure you picked on the slicer.

The SWITCH then gets the equivalent measure value

 

Add the Sorter to your your clustered bar chart as tootltip.

The click on three dots [...], Sort axis, Sorter, Descending

speedramps_1-1737383720525.png

 

Change the measure to handle multiple selections if required, so it slected you prefered measure sort sequence.

 

Please click [accept solution] and thumbs up buttons to show your appreciation.

 

 

I did the same earlier, but somehow I missed the order sequence. It is working as I expected now. Thank you.

DataNinja777
Super User
Super User

Hi @RamyaKrishna_61 ,

 

To address the issue of sorting a clustered bar chart in Power BI when using field parameters for both the x-axis and y-axis, you can create a dynamic sorting measure using DAX. This issue arises because field parameters change the underlying data in the visual, which can cause the sort order to reset when parameters are switched. The solution involves creating a DAX measure that dynamically determines the value to be used for sorting, based on the selected parameter. For example, you can use a SWITCH function in the measure to return the relevant measure's value depending on the active selection from the field parameter. Once the measure is created, it can be added to the visual without being displayed, and you can configure the chart to sort by this measure in ascending or descending order as needed. This ensures that the sort order adapts dynamically to changes in the selected field parameter. To further enhance the user experience, you can also provide an option for users to explicitly select a sorting preference through a slicer. By anchoring the sort logic to a consistent calculated measure, this approach resolves the issue and ensures the visual maintains the desired sort order regardless of parameter changes.

 

Best regards,

Can you give an example. I have created a field parameter with units and units YOY na dcreated a clustered col chart for this for each commodity(x axis is fixed). The parameter selection is resetting the sort order. Is there a way I can fix the sort order to Units YOY sort descending using a measure. I am new to PBI so still in learning phase. 

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount! Prices go up Feb. 11th.

Jan25PBI_Carousel

Power BI Monthly Update - January 2025

Check out the January 2025 Power BI update to learn about new features in Reporting, Modeling, and Data Connectivity.

Jan NL Carousel

Fabric Community Update - January 2025

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