Check your eligibility for this 50% exam voucher offer and join us for free live learning sessions to get prepared for Exam DP-700.
Get StartedDon'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.
I need your help to be able to create a line chart that shows two lines, one for the current 12 months rolling period, and another one that shows the prior rolling 12 months. The intended results should always show the current month on the right-hand side of the graph (for example the current 12 months as of today are from April 2022 to March 2023)
This is what I have tried so far: To show two lines of the current twelve months period and compare the same period with the prior dates in the same line chart graph in Power BI, I followed these steps below:
Create a measure to calculate the current rolling twelve months values for your Y-axis measure. In my case, the measure is "Appointments in Current 12M". Using the DATESBETWEEN function I calculated the values for the past 12 months.
Appointments in Current 12M = CALCULATE( DISTINCTCOUNT(SalesActivation[LocationCodes]), DATESBETWEEN( SalesActivations[periode_date], DATEADD(MAX(SalesActivation[periode_date]),-11,MONTH), MAX(SalesActivation[periode_date]) ), FILTER(SalesActivation, SalesActivation[OrganiserData]="1") )
Then I created a measure to calculate the prior rolling twelve months' values for my Y-axis measure. Using the SAMEPERIODLASTYEAR function in combination with DATESBETWEEN to calculate the values for the same period in the previous year.
Appointments in Prior 12M = CALCULATE( DISTINCTCOUNT(SalesActivation[LocationCodes]), SAMEPERIODLASTYEAR(SalesActivation[periode_date]), DATESBETWEEN( SalesActivation[periode_date], DATEADD(MAX(SalesActivation[periode_date]),-23,MONTH), DATEADD(MAX(SalesActivation[periode_date]),-12,MONTH) ), FILTER(SalesActivation, SalesActivation[OrganiserData]="1") )
Create a measure for the X-axis values. In my case, the measure is "Period".
Period = FORMAT(SalesData[periode_date], "mmm yyyy")
I then created a line chart visual in Power BI. I dragged the "Period" measure to the Axis field well, and the two measures I created earlier to the Values field well. This should display two lines representing the current rolling twelve months values and the prior rolling twelve months values, respectively, and compare them in the same line chart graph in Power BI, but the results and calculations did not work for me. Kindly provide me with your valuable assistance.
Solved! Go to Solution.
I managed to resolve the problem by creating the following two measures for the Y Axis
@Jack_Reacher Try the technique here. You can switch this to 12 months by editing the -3 in EOMONTH to -12 and changing the AVERAGEX to SUMX: Better Rolling Average - Microsoft Power BI Community
Better Rolling Average =
VAR __EndDate = MAX('Table'[Date])
VAR __3MonthsAgo = EOMONTH(__EndDate, -3)
VAR __StartDate = DATE(YEAR(__3MonthsAgo), MONTH(__3MonthsAgo), 1)
VAR __Table =
SUMMARIZE(
FILTER(ALL('Table'),[Date]>=__StartDate && [Date]<=__EndDate),
'Table'[Month],
"__Value",SUM('Table'[Value])
)
RETURN
AVERAGEX(__Table,[__Value])
Thank you for sharing Greg, nonetheless, this calculation did not resolve my problem, I still could not display the current 12 rolling months and the prior rolling 12 months on the same line chart.
I managed to resolve the problem by creating the following two measures for the Y Axis
this measure is giving error
March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!
Check out the January 2025 Power BI update to learn about new features in Reporting, Modeling, and Data Connectivity.
User | Count |
---|---|
124 | |
79 | |
50 | |
38 | |
38 |
User | Count |
---|---|
196 | |
80 | |
70 | |
51 | |
42 |