cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Highlighted
Anonymous
Not applicable

Rolling SUM with Datesbetween where Initial Date is blank - Error

Hello,

I have one measure which is the following:

Margin = DIVIDE(CALCULATE([Margin],KEEPFILTERS('Program'[Model]="Y")),[Margin PM],BLANK())


And I made two rolling sum measures, one using a SUMX and the other SUM.

RollingMargin(SUM) = var between = 
DATESBETWEEN( 
        'Date'[Date],
DATEADD(FIRSTDATE('Date'[Date]),-6,MONTH),
        LASTDATE (PREVIOUSMONTH('Date'[Date])))

return
CALCULATE([Margin],between)
RollingMargin(SUMX) = 
var between = 
DATESBETWEEN( 
        'Date'[Date],
DATEADD(FIRSTDATE('Date'[Date]),-6,MONTH),
        LASTDATE (PREVIOUSMONTH('Date'[Date])))
return CALCULATE(SUMX(VALUES('Date'[MonthID]),[Margin]),between)


As displayed in the image below, given there is no data in January, using the SUM with datesbetween yields only null values, I assume because the range includes a non-existing Date as 1st parameter, or maybe cause of the base measure is using DIVIDE (which I changed to alternate result as 0 and got the same result as below, but instead of blank, zeros).

The 2nd Table is using a 1 Month interval.
If I would use a 12 Month interval then for SUM everything would be blank
Is there a way to avoid this? I would like to use SUM as it yields results faster.

forum.PNG

Thank you!




 

5 REPLIES 5
Highlighted
Super User IV
Super User IV

Re: Rolling SUM with Datesbetween where Initial Date is blank - Error

In case of non-continuous date prefer calculation like the one given below 

 

Var _last_year= (max('Date'[Date Filer]))-365
Var   _This_year=year(max('Date'[Date Filer]))
Var _min_last_year= (maxx('Date',STARTOFYEAR(DATEADD('Date'[Date Filer],-12,MONTH))))
Var   _min_This_year=year(max(STARTOFYEAR('Date'[Date Filer])))

Var _last_year_val= CALCULATE(sum(Sales[Sales Amount]),(Sales[Sales Date])<=_last_year && (Sales[Sales Date]) >=_min_last_year)
Var   _This_year_val =CALCULATE(sum(Sales[Sales Amount]),(Sales[Sales Date])<=_This_year && (Sales[Sales Date]) >=_min_This_year)
return
(_This_year_val-_last_year_val)/_last_year_val*100

 



Did I answer your question? Mark my post as a solution! Appreciate your Kudos!!
My Recent Blog -Week is not so Weak Connect on Linkedin

Proud to be a Super User!

Highlighted
Anonymous
Not applicable

Re: Rolling SUM with Datesbetween where Initial Date is blank - Error

My Margin formula its a SUM of a column, did I mistake up top.

Margin = DIVIDE(CALCULATE(SUM(Table[Values]),KEEPFILTERS('Program'[Model]="Y")),[Margin PM],BLANK())

Highlighted
Community Support
Community Support

Re: Rolling SUM with Datesbetween where Initial Date is blank - Error

Hi @Anonymous ,


To use Time intelligence function, Continuous time is necessary for most time. you can try to generate a calendar table and using in your DAX.

 

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

19.PNG

 

The two formulas seems have same result on my side, Could you please provide more details about it?

 

18.PNG

 

 

 

BTW, pbix as attached.

 

Best regards,

Community Support Team _ Dong Li
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Community Support Team _ Dong Li
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Highlighted
Community Support
Community Support

Re: Rolling SUM with Datesbetween where Initial Date is blank - Error

Hi @Anonymous ,

 

How about the result after you follow the suggestions mentioned in my original post?Could you please provide more details about it If it doesn't meet your requirement?

 

Best regards,

Community Support Team _ Dong Li
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Community Support Team _ Dong Li
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Highlighted
Helper II
Helper II

Re: Rolling SUM with Datesbetween where Initial Date is blank - Error

Hi again,

Sorry for the late response. You used a static value for Margin PM.
Use this formula instead and you will get the same issue I am talking about:

Margin PM = CALCULATE(SUM('Table'[Values]),PREVIOUSMONTH('Date'[Date]))
I think this is only possible via Sumx. 
Thanks!

Helpful resources

Announcements
Community Blog

Community Blog

Visit our Community Blog for articles, guides, and information created by fellow community members.

Using the Community

Using the Community

Need help with the Power BI Community? Our 'Using the Community' support articles are a great place to start.

Galleries

Galleries

Looking for inspiration on how to present your data? Need instructional videos? Check out our Galleries!

Community Summit North America

Community Summit North America

Innovate, Collaborate, Grow. The top training and networking event across the globe for Microsoft Business Applications

Top Solution Authors
Top Kudoed Authors