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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
Flo1
Advocate I
Advocate I

Incorrect Max value due to different sorting

Hi Community,

 

I try to create a line chart with Total Sales by Year-Month column and an additionally constant line giving the maximum of Total Sales (Global Max).

 

I have this simple data model and date table: 

 DataModel.pngDataTable.png

 

I get the line chart below which is almost perfect but has a wrong (alphabetic) sort order in x axis:

Correct Max Line, wrong sort order in x axis.Correct Max Line, wrong sort order in x axis.

If I change the sort order of my Year-Month column in my date table and sorting it by YearMonthKey, the Global Max line in my chart gets broken and I see this:

correct x axis sorting - wrong max linecorrect x axis sorting - wrong max line

My question is: what's wrong here?

 

The definiton for my Global Max measure is:

 

 

Global Max = 
MAXX(
    ALL('Date'[Year-Month]),
    [Total Sales]
)

 

 

 

Thanks for your help!

1 ACCEPTED SOLUTION

@amitchandak Thank you for your response!
Your solution helps!

I found also another solution. If I sort Year-Month column by YearMonthKey it also helps to include the sort by-column in my measure like here:

Global Max = 
MAXX(
    ALL('Date'[Year-Month], 'Date'[YearMonthKey]),
    [Total Sales]
)

View solution in original post

2 REPLIES 2
amitchandak
Super User
Super User

@Flo1 , Try like

 

Global Max =
calculate( MAXX(
values('Date'[Year-Month]),
[Total Sales]
), allselected())

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

@amitchandak Thank you for your response!
Your solution helps!

I found also another solution. If I sort Year-Month column by YearMonthKey it also helps to include the sort by-column in my measure like here:

Global Max = 
MAXX(
    ALL('Date'[Year-Month], 'Date'[YearMonthKey]),
    [Total Sales]
)

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

November Power BI Update Carousel

Power BI Monthly Update - November 2025

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

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.