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

Find everything you need to get certified on Fabric—skills challenges, live sessions, exam prep, role guidance, and more. Get started

Reply
Jack_Reacher
Helper II
Helper II

How to sort months by names on two rolling 12 months using DAX measures in a line chart

Hello Power BI Community,

 

I am facing an issue with the x-axis on my line chart in Power BI. Specifically, when I apply the "PeriodCal" dax measure, the months for 2023 are shown on the left side of the line chart, while the months of the year 2022 are shown on the right side of the line chart in no specific order. I want to reverse the order so that the months for 2022 are shown on the left side and the months for 2023 are shown on the right side. I also attempted to sort the x-axis by "Current 12 months rolling" and "Prior 12 months rolling" (and by PeriodCal also) but to no avail. My objective is to sort the months from left (oldest month) to right (newest month) in a rolling 12 months format (March 2022, April ... December 2022, .... Jan 2023... March 2023) 

Jack_Reacher_0-1682956559007.png


Here is the code I attempted so far for the "PeriodCal" new column I am using:

PeriodCal = VAR __maxDate = MAX(Calendrier[Date]) VAR __minDate = MIN(Calendrier[Date]) RETURN SWITCH( TRUE(), 
Calendrier[Date] = __maxDate, "Current Month", Calendrier[Date] = __minDate, "Oldest Month",
FORMAT(Calendrier[Date], "mmm yyyy") )

The following are my two measures applied to the graph to calculate the prior and current 12 months rolling :

 

Prior rolling 12 months = CALCULATE([DAX_Measure_Sales], DATESINPERIOD('Calendrier'[Date],ENDOFMONTH(dateadd(Data[MyDate],-12,month)),-12,MONTH))
Current rolling 12 months = CALCULATE([DAX_Measure_Sales], DATESINPERIOD('Calendrier'[Date], ENDOFMONTH(Data[MyDate]), -12, MONTH))
 

I would greatly appreciate any help or suggestions on how to fix this issue.

 

Thank you!

0 REPLIES 0

Helpful resources

Announcements
Europe Fabric Conference

Europe’s largest Microsoft Fabric Community Conference

Join the community in Stockholm for expert Microsoft Fabric learning including a very exciting keynote from Arun Ulag, Corporate Vice President, Azure Data.

AugPowerBI_Carousel

Power BI Monthly Update - August 2024

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

August Carousel

Fabric Community Update - August 2024

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

Top Kudoed Authors