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
SammyNed
Helper I
Helper I

3 full months trailing graph

Hi Everyone

 

Can someone please assist?

 

My stakeholders are excel lovers and want a view as below (dummy excel data).

 

If they select a month in the slicer, then the graph must show

  • the trailing 3 months of sales and previous year sales;
  • and then the forecast and target for that selected slicer month.

 

 

SammyNed_2-1722332121144.png

 

SammyNed_1-1722332104610.png

 

My attempts:

 

So i created a seperate date table, that does not have a relationship to the other tables and then referenced it in the measure below to get the sales for the selected slicer date (and 3 months trailing).

 

3MonthSales =
    VAR CurrentDate = MAX('Previous Date'[EndofMonth])
    VAR SelectedDate = DATE(YEAR(CurrentDate),MONTH(CurrentDate)-3,DAY(CurrentDate))
    VAR Result =
    CALCULATE(sum[sales],
    Filter( Table,table[date]>= SelectedDate && Table[date]<= CurrentDate))
RETURN
Result
 
Problem 1:
However practically i get more or sometimes less than 3 exact months, as seen in the powerbi graph below. I believe this is because of the number of days in a month, but i want the full 3 months (selected month and 2 prior; if the selected month is not complete yet, then still only show me the incomplete month and 2 full months prior.)
 
Problem 2:
How can I get the previous year sales, this calculation does not work for previous year?
SammyNed_3-1722335833200.png

 

Thanking you in advance

 

😁

 

1 ACCEPTED SOLUTION
v-kaiyue-msft
Community Support
Community Support

Hi @SammyNed ,

 

Thanks for the reply from @SachinNandanwar , please allow me to provide another insight: 

 

I use these sample data to demonstrate.

vkaiyuemsft_0-1722404779376.png

 

1. create a calculation table. And adjust the date format.

Table =
DISTINCT(‘financials’[Date])

vkaiyuemsft_1-1722404809196.png

 

2. create MEASURE.

MEASURE =
VAR _cur_mon =
EOMONTH ( SELECTEDVALUE ( ‘Table’[Date] ), 0 )
VAR _3_mon =
EOMONTH ( SELECTEDVALUE ( ‘Table’[Date] ), -3 ) + 1
RETURN
IF (
MAX ( ‘financials’[Date] ) <= _cur_mon
&& MAX ( ‘financials’[Date] ) >= _3_mon,
1
)


3. Filter the data in the bar chart where MEASURE is 1.

vkaiyuemsft_2-1722404866955.png

 

If your Current Period does not refer to this, please clarify in a follow-up reply.

 

Best Regards,

Clara Gong

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

3 REPLIES 3
v-kaiyue-msft
Community Support
Community Support

Hi @SammyNed ,

 

Thanks for the reply from @SachinNandanwar , please allow me to provide another insight: 

 

I use these sample data to demonstrate.

vkaiyuemsft_0-1722404779376.png

 

1. create a calculation table. And adjust the date format.

Table =
DISTINCT(‘financials’[Date])

vkaiyuemsft_1-1722404809196.png

 

2. create MEASURE.

MEASURE =
VAR _cur_mon =
EOMONTH ( SELECTEDVALUE ( ‘Table’[Date] ), 0 )
VAR _3_mon =
EOMONTH ( SELECTEDVALUE ( ‘Table’[Date] ), -3 ) + 1
RETURN
IF (
MAX ( ‘financials’[Date] ) <= _cur_mon
&& MAX ( ‘financials’[Date] ) >= _3_mon,
1
)


3. Filter the data in the bar chart where MEASURE is 1.

vkaiyuemsft_2-1722404866955.png

 

If your Current Period does not refer to this, please clarify in a follow-up reply.

 

Best Regards,

Clara Gong

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

thank you @v-kaiyue-msft . This really helped. I think my issue was with the date table (it was in days and not months)

SachinNandanwar
Super User
Super User

Please go through this article

https://www.sqlbi.com/articles/rolling-12-months-average-in-dax/



Regards,
Sachin
Check out my Blog

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.