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

Grow your Fabric skills and prepare for the DP-600 certification exam by completing the latest Microsoft Fabric challenge.

Reply
semidevil
Helper I
Helper I

how to dynamically get last six months of data

My dates in my data are 1/1/2015, 2/1/2015, 3/1/2015........12/1/2017.

 

I want to create a chart that will show me the last six months of data, and when the next months roll around, it will automatically adjust and get 6 months of data from the updated month.

 

I have a column called "MaxMonth" that will always output the most most recent month,

I have a measure that will retrieve the last 6 months worth of data, using my "MaxMonth" as the starting point.

 

6Months = CALCULATE(SUM(Value),DATEADD(Date[MaxDate], -6,Month))

 

I expected this to give me what I need, but it did not.

What went wrong?

1 ACCEPTED SOLUTION
RolandsP
Resolver IV
Resolver IV

If want to calculate running total for last 6 month, you should use function DATESINPERIOD, instead of DATESADD (it will give you value for 6 month ago).

 

Try this measure:

6Months = CALCULATE(SUM(Value), DATESINPERIOD(Date[Date], -6, MONTH)).

 

Please make sure you have a Date table in your model. Without that Time intelligence function will not work.

View solution in original post

3 REPLIES 3
Anonymous
Not applicable

I have the similar query, 

Is there anyone know how I can dynamically select last 6 month or 3 months value to make a trend line. It is posible in excel by offset formula but here need exparts help. 

 

Thanks in advance for your answers. 

RolandsP
Resolver IV
Resolver IV

If want to calculate running total for last 6 month, you should use function DATESINPERIOD, instead of DATESADD (it will give you value for 6 month ago).

 

Try this measure:

6Months = CALCULATE(SUM(Value), DATESINPERIOD(Date[Date], -6, MONTH)).

 

Please make sure you have a Date table in your model. Without that Time intelligence function will not work.

Above solution wont work as of 2022.

 

SUM_of_last_6month = calculate (sum('table'[sumvalue]) ,DATESINPERIOD(table[datefield], max(table[datefield]),-6, MONTH))
 
In here: 
DATESINPERIOD( table[datefield], max(table[datefield]), -6 , MONTH)
this will get dates from last six months

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.

RTI Forums Carousel3

New forum boards available in Real-Time Intelligence.

Ask questions in Eventhouse and KQL, Eventstream, and Reflex.