Forum Discussion
Dynamic Last 7 day
Anonymous I am trying to create a dynamic measure not column.
Hi vanessa,
You can try to use below formula to calculate the last 7 day sales:
Last 7 Day Sales =
var seleted=LASTDATE(ALLSELECTED('Fact table'[Date]))
return
CALCULATE(SUM('Fact table'[Sales]),FILTER(ALL('Fact table'),'Fact table'[Date]>=seleted-7&&'Fact table'[Date]<=seleted))
Regards,
Xiaoxin Sheng
- Rameshwar9 years agoFrequent Visitor
Hi Anonymous
Your formula works correctly in PowerBI Desktop when I have In Memory data.
However, its not working when I've PowerBI Desktop conected to SSAS Tabular instance (1103 compatibility - SQL2014) with Direct Query connection. It gives me syntax error for VAR function.
Is VAR function not supported in SSAS, specifically to 1103 compatibility level?
Thanks for your help!
Thanks,
Rameshwar
- Anonymous9 years agoNot applicable
Hi,
If you are working with a date table, you could also create a calculated column within the date table that's is called 'IsLast7Days'. The column value equals true for every day that's within last 7 days. Based on that, you can create a calculation including a filter (Where IsLast7Days equals true).
- Rameshwar9 years agoFrequent Visitor
Anonymous
The Calculated column will not work here. This Measure needs to be dynamic. The user might select any date from Slicer and depending upon that we should go back previous 7 days.
- TomMartens9 years agoSuper User
Hey,
VAR is not supported in SQL Server 2014 as stated here:
https://msdn.microsoft.com/en-us/library/mt243785.aspx
and also have a look here:
Regards
- Rameshwar9 years agoFrequent Visitor
- Anonymous8 years agoNot applicable
Hi Rameshwar,
Were you able to resolve this issue? I'm trying to write a DAX formula involving VAR in Power BI desktop connected to a SSAS Tabular data model and also getting a syntax error when there's actually no error that I can see in my syntax.
Thanks for your input
Esteban