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
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
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.