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
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
v-lid-msft
Community Support
Community Support

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.
Anonymous
Not applicable

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!
v-lid-msft
Community Support
Community Support

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.
Anonymous
Not applicable

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())

amitchandak
Super User
Super User

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

 

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.