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

Earn the coveted Fabric Analytics Engineer certification. 100% off your exam for a limited time only!

Reply
IanLittlejohn
New Member

DatesInPeriod with Leap Year

I'm using a DatesInPeriod with an =Calculate formula.  The DatesInPeriod goes 6 months back,  This works perfectly, except for Feb 2016 which is a leap year.  It calculates 7 months.  Has anybody else had this problem with the leap year?  

5 REPLIES 5
Ashish_Mathur
Super User
Super User

Hi,

 

Try this measure

 

=CALCULATE(SUM(Data[Value]),EDATE(MIN(Calendar[Date]),-6))

 

There should be a relationship from the Date column of the Data Table to the Date column of the Calendar Table.  Ensure that in the filter or slicer, you select any one month.

 

Hope this helps.


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/

Hi Ashish, I tied using the edate but it returns one value for the last 6 months.  I'm looking for a rolling 6 months total to be calculated. Thanks for the suggestion

v-juanli-msft
Community Support
Community Support

Hi @IanLittlejohn

How do you write the formula? it is a calculated column or a measure?

Could you share me the formula nad the screenshot when apply the formula?

 

I test with the following formula, it calculate the value from 2015/9/1~2016/2/29, Does this meet your need?

Column = CALCULATE(SUM(Sheet2[value]),DATESINPERIOD(Sheet2[date],DATE(2016,2,29),-6,MONTH))

 

 

Best Regards

Maggie

Hi Maggie,

 

Thanks for the suggestion.  I'm using a rolling calculation for the last 6 months sales.  I'm passing the end date as a variable from another table.

 

T6 Months Sales =

var lastsaledate = lastdate('Data'[Date])
Return
CALCULATE([Sales Total],all('Date Master Table'),DATESINPERIOD('Date Master Table'[Master Date],lastsaledate,-6,MONTH))

 

So I'm not able to hard code the starting date as per your suggestion

Hi @IanLittlejohn

I make a test on my site as below

for 2016/2, it calculates the last 6 months sales between 2015/9~2016/2

for 2016/7,  it calculates the last 6 months sales between 2016/2~2016/7

Is my test correct?

8.png

 

 

Could you provide some screenshot on your side for better analysis?

 

Additionally, here are some other methods about rolling 6 months sum

https://www.kasperonbi.com/show-only-the-sales-for-the-last-12-months/

https://community.powerbi.com/t5/Desktop/Calculate-Moving-Average-Last-6-Month-with-not-sequencial-D...

https://stackoverflow.com/questions/50357343/power-bi-rolling-6-month-sum

 

Best Regards

Maggie

 

Helpful resources

Announcements
April AMA free

Microsoft Fabric AMA Livestream

Join us Tuesday, April 09, 9:00 – 10:00 AM PST for a live, expert-led Q&A session on all things Microsoft Fabric!

March Fabric Community Update

Fabric Community Update - March 2024

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