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.
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.
Thank you!
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.
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.
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]))
The two formulas seems have same result on my side, Could you please provide more details about it?
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.
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())
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
Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City
Check out the April 2024 Power BI update to learn about new features.
User | Count |
---|---|
114 | |
99 | |
83 | |
70 | |
60 |
User | Count |
---|---|
150 | |
115 | |
104 | |
89 | |
65 |