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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
Niraj_vora0106
Helper III
Helper III

Trend of last 12 months

Hi community, 

 

I've a query which I'm trying to solve. 

 

Suppose I'm in April 2022 and I want trend of last 12 months,

ie : from April 2021 to March 2022. and I want it to be dynamic if I select May 2022 it should range from May 2021 to April 2022.

 

Please help!

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

Hi @Niraj_vora0106 ,

 

1. You could simply apply Relative Date slicer to filter values based on current day:

Eyelyn9_0-1652084565669.png

 

2. If you want to dynamically change visuals based on date selection, please firtstly add a Date table for slicer:

For Slicer = CALENDAR(MIN('Table'[Date]),MAX('Table'[Date]))

Then create a flag measure for visual-filter:

Flag = 
var _diff=DATEDIFF(MAX('Table'[Date]),MAX('For Slicer'[Date]),MONTH)
return IF( _diff>0 && _diff<=12,1,0)

Eyelyn9_1-1652084899981.png

Best Regards,
Eyelyn Qin
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

2 REPLIES 2
v-eqin-msft
Community Support
Community Support

Hi @Niraj_vora0106 ,

 

1. You could simply apply Relative Date slicer to filter values based on current day:

Eyelyn9_0-1652084565669.png

 

2. If you want to dynamically change visuals based on date selection, please firtstly add a Date table for slicer:

For Slicer = CALENDAR(MIN('Table'[Date]),MAX('Table'[Date]))

Then create a flag measure for visual-filter:

Flag = 
var _diff=DATEDIFF(MAX('Table'[Date]),MAX('For Slicer'[Date]),MONTH)
return IF( _diff>0 && _diff<=12,1,0)

Eyelyn9_1-1652084899981.png

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

PC2790
Community Champion
Community Champion

Hey 

You can use DATESINPERIOD DAX function here.

You can do something like this

TotalSalesinPeriod = CALCULATE([Total Sales],DATESINPERIOD(DatesTable[Date],MIN(DatesTable[Date]),-12,MONTH))​

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

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

April Fabric Community Update

Fabric Community Update - April 2024

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