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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
kkashiv
Frequent Visitor

Sorting stacked bar chart by total not correct for calculated measure

PowerBI novice here. I have a measure named 'Measure_2' that displays this information where commodity( Electric, Natural Gas, Steam, etc) is the legend for stacked bar chart.

kkashiv_0-1686014007347.png

 

This is the data in a tabular format.

kkashiv_1-1686014080326.png


I would like to sort this by the total of all columns for individual Building. Basically keep the longest bar first. 
I have selected the sort by Measure 2 in descending order 

kkashiv_2-1686014195070.png


However this doesnt sort the stacked bar chart in the correct order even though the totals above each bar is correct. Is there a way to achieve this?

 

 

1 ACCEPTED SOLUTION

Hi,

Please kindly check if the below measure works as expected with showing the correct numbers.

Measure_2 =
SUMX (
    SUMMARIZE ( Data, Buildings[Buildings], Commodity[Commodity] ),
    IF (
        Commodity[Commodity] = "Electric",
        [Value measure:] * 3.412,
        IF (
            Commodity[Commodity] = "Natural Gas",
            [Value measure:] * 100,
            IF (
                Commodity[Commodity] = "Steam",
                [Value measure:] * 1194,
                IF (
                    Commodity[Commodity] = "Chilled Water",
                    Data[Value measure:] * 12,
                    [Value measure:]
                )
            )
        )
    )
)

If this post helps, then please consider accepting it as the solution to help other members find it faster, and give a big thumbs up.


Go to My LinkedIn Page


View solution in original post

6 REPLIES 6
Jihwan_Kim
Super User
Super User

Hi,

I am not sure how your datamodel looks like, but I tried to create a sample pbix file like below.

Please check the below picture and the attached pbixfile.

 

Jihwan_Kim_0-1686021783067.pngJihwan_Kim_1-1686021794616.png

 

 

If this post helps, then please consider accepting it as the solution to help other members find it faster, and give a big thumbs up.


Go to My LinkedIn Page


Thanks for replying. Your data model is exactly similar to mine. The only difference is that I am using a measure called 'Measure_2' that utilizes another measure 'Bill_line_items_value' and converts values to the same unit. 

DAX expression of the measure:

kkashiv_0-1686023194120.png

 

 

If I use the original measure 'Bill_line_item_value', it sorts the bars correctly:-

kkashiv_1-1686023296918.png


The sorting is failing for the new measure 'Measure_2' I created for standardizing the values. 

 

Using your PBIX file, I created a similar measure. It messes up the sorting with your data too.

kkashiv_0-1686024348835.pngkkashiv_1-1686024374140.png

Attaching the pbix file with the measure: kkashiv.pbix
Is it because of the DAX expression?

Hi,

Please kindly check if the below measure works as expected with showing the correct numbers.

Measure_2 =
SUMX (
    SUMMARIZE ( Data, Buildings[Buildings], Commodity[Commodity] ),
    IF (
        Commodity[Commodity] = "Electric",
        [Value measure:] * 3.412,
        IF (
            Commodity[Commodity] = "Natural Gas",
            [Value measure:] * 100,
            IF (
                Commodity[Commodity] = "Steam",
                [Value measure:] * 1194,
                IF (
                    Commodity[Commodity] = "Chilled Water",
                    Data[Value measure:] * 12,
                    [Value measure:]
                )
            )
        )
    )
)

If this post helps, then please consider accepting it as the solution to help other members find it faster, and give a big thumbs up.


Go to My LinkedIn Page


Yes this works. Thank you so much. I would like to understand the difference in the DAX expression. What exactly changed?

Hi,
It changed to produce the total number of each building. If you try to change the visualization to a table visualization, and if you see the Total Row in the visualization, two measures show different total number. 

I think, the one you provided showed correct numbers in each row, however, it showed an incorrect number in the total row.

If this post helps, then please consider accepting it as the solution to help other members find it faster, and give a big thumbs up.


Go to My LinkedIn Page


Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

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

Top Solution Authors