Forum Discussion
Dynamic Last 7 day
the formula works fine when I hardcode the value as below:
7day_Sales =
VAR selected_Date = IF(HASONEVALUE('Table'[Date]),2017/07/18),TODAY())
RETURN
CALCULATE(SUM('Table'[Sales]),FILTER('Table','Table'[Date]< [selected_Date] &&'Table'[Date]>= [selected_Date]-7))
But when I try using VALUES('Table'[Date]) instead hardcoding the date, the measure returns data for all the dates in the table.
Is this because the left and right side of the filter condition are hitting the same table?
HI vanessa,
Power bi not support dynamic calculated columns based on slicer, you can create dynamic measure based on slicer.
In addition, you can use query parameter to create a dynamic calculated column on power query.
Deep Dive into Query Parameters and Power BI Templates
Regards,
Xiaoxin Sheng
- vanessa9 years agoPost Patron
Anonymous I am trying to create a dynamic measure not column.
- Anonymous9 years agoNot applicable
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