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

Get Fabric Certified for FREE during Fabric Data Days. Don't miss your chance! Request now

Reply
kaileena
Frequent Visitor

dynamically show last x months - correct dax formula

Hello!

 

I think i am very close to what I want. But I think my dax is incorrect.

When i select a date from the slicer, i want to see the last 12 month wrt slicer selection. 

 

Example: slicer selection january 2021 => the graph shows from february 2020 to january 2021.

 

I know the question was asked before. I tried to customise my dax accoordingly. But I have a question:

I have a lot of graphs that are time relative so x axis is 'Date' on all of them. This 'Date' comes from 'calendar' table which is used also for slicer. If i create a new time table for the slicer, independent from the other tables,  how do i ensure connectivity with the other grahs?

 

thank you for your kindness

kaileena_0-1658069310896.png

kaileena_0-1658498359975.png

 

kaileena_2-1658069528709.png

 

 

dax

Minus12Month =
CALCULATE (
SUM('Measurement'[Value]),
'Measurement'[Type] IN { "Budget Planned" },
FILTER (
ALL ( 'Calendar'[Date] ),
[Date] > EOMONTH ( MAX ( [Date] ), -12 )
&& [Date] <= EOMONTH ( MAX ( [Date] ), 0 )
)
)

 

1 ACCEPTED SOLUTION
v-jingzhang
Community Support
Community Support

Hi @kaileena 

 

Your DAX is to calculate the cumulative total in the last 12 months previous of the selected month rather than to show the values of the last 12 months. You need to have a new date table for the slicer and keep it independent from other tables. Then create a measure to compare the selected value from the slicer to the dates in other visuals. Put date column from calendar table into other visuals. 

vjingzhang_0-1658284208908.png

Date Filter = 
VAR maxDate = MAX('Period Slicer'[Date])
VAR minDate = EOMONTH(MAX('Period Slicer'[Date]),-12)
RETURN
IF(MAX('Date'[Date])>minDate && MAX('Date'[Date])<=maxDate, 1, 0)

 

Then add this measure on the visual as a filter. Set it to show items when value is 1. 

vjingzhang_1-1658284620711.png

 

I have attached a sample pbix at bottom. Hope it helps.

 

Best Regards,
Community Support Team _ Jing
If this post helps, please Accept it as Solution to help other members find it.

View solution in original post

1 REPLY 1
v-jingzhang
Community Support
Community Support

Hi @kaileena 

 

Your DAX is to calculate the cumulative total in the last 12 months previous of the selected month rather than to show the values of the last 12 months. You need to have a new date table for the slicer and keep it independent from other tables. Then create a measure to compare the selected value from the slicer to the dates in other visuals. Put date column from calendar table into other visuals. 

vjingzhang_0-1658284208908.png

Date Filter = 
VAR maxDate = MAX('Period Slicer'[Date])
VAR minDate = EOMONTH(MAX('Period Slicer'[Date]),-12)
RETURN
IF(MAX('Date'[Date])>minDate && MAX('Date'[Date])<=maxDate, 1, 0)

 

Then add this measure on the visual as a filter. Set it to show items when value is 1. 

vjingzhang_1-1658284620711.png

 

I have attached a sample pbix at bottom. Hope it helps.

 

Best Regards,
Community Support Team _ Jing
If this post helps, please Accept it as Solution to help other members find it.

Helpful resources

Announcements
Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

October Power BI Update Carousel

Power BI Monthly Update - October 2025

Check out the October 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.