Forum Discussion
Display data for dates relative to date selected in table
Anonymous this is pretty difficult to try to debug without any sample data to work with, but the thing that immediately jumps out to me in your second measure are the RevenueCalc/Revenue and COSCloudCalc/COSCloud variables.
I don't think you can reference a variable within a CALCULATE function as you are doing there. My understanding is that once the "Calc" variables have been declared and evaluated, they are treated as constants in subsequent variables, until a RETURN statement is reached. That is, they would not be affected by CALCULATE modifiers.
I would recommend combining the "calc" variables into a single step which contains the necessary date filter modifiers to select the previous month.
Enterprise DNA has an excellent video explaining the concept of "variables as constants", which I think is what you are running into here.
What does "Variables Are Constants" Really Mean?
- Anonymous4 years agoNot applicable
Anonymous , thank you for taking the time to look over this. I can confirm that those values do calculate correctly, it is only that they are not calculating for the correct timeframe.
- Anonymous4 years agoNot applicable
Anonymous Did you watch the video I linked? I think it describes exactly what you are seeing here... Let me try to explain a different way...
Take your Revenue variable for example:
VAR Revenue = CALCULATE(RevenueCalc, REMOVEFILTERS('Date'), KEEPFILTERS(SelPeriod), USERELATIONSHIP('Date'[Date], 'Calendar'[Date]))The "KEEPFILTERS" modifier is what is supposed to be adjusting the timeframe. But it has no effect, because "RevenueCalc" is treated as a constant, and therefore cannot be affected by a CALCULATE modifier. You need to combine the Revenue and RevenueCalc variables into a single variable (and same with your COSCloud and COSOther variables).
- Anonymous4 years agoNot applicable
Anonymous Thank you so much for the clarification, I understood that better than I did the video. I've adjusted the calculations to be:
VAR MonthEndDate = SELECTEDVALUE('Date'[MonthEndDate])VAR AdjMonth = DATEADD('Date'[MonthEndDate], -1, MONTH)VAR SelPeriod = CALCULATETABLE(VALUES('Calendar'[MonthEndDate]),'Calendar'[MonthEndDate]=AdjMonth)VAR Revenue = CALCULATE(SUM(Transactions[Net Change]), FILTER(Transactions, Transactions[Source]="Actual"), FILTER(Mapping, Mapping[PLcalc] = "Revenue")*-1, REMOVEFILTERS('Date'), KEEPFILTERS(SelPeriod), USERELATIONSHIP('Date'[Date], 'Calendar'[Date]))VAR COSCloud = CALCULATE(SUM(Transactions[Net Change]), FILTER(Transactions, Transactions[Source]="Actual"), FILTER(Mapping, Mapping[PLcalc] = "COS - Cloud"), REMOVEFILTERS('Date'), KEEPFILTERS(SelPeriod), USERELATIONSHIP('Date'[Date], 'Calendar'[Date]))VAR COSOther = CALCULATE(SUM(Transactions[Net Change]), FILTER(Transactions, Transactions[Source]="Actual"), FILTER(Mapping, Mapping[PLcalc] = "COS - Other"), REMOVEFILTERS('Date'), KEEPFILTERS(SelPeriod), USERELATIONSHIP('Date'[Date], 'Calendar'[Date])).....RETURNSWITCH (TRUE (),MAX('ReportConfig'[PLvar3]) = "blank", "",MAX('ReportConfig'[PLvar3]) = "Revenue", FORMAT(Revenue, "$#,###;($#,###)"),MAX('ReportConfig'[PLvar3]) = "COSCloud", FORMAT(COSCloud, "#,###;(#,###)"),MAX('ReportConfig'[PLvar3]) = "COSOther", FORMAT(COSOther, "#,###;(#,###)"),......)Now I'm getting the error:
A function 'FILTER' has been used in a True/False expression that is used as a table filter expression. This is not allowed.
Do you think this error is to do with the SelPeriod variable? I used this approach (remove date filters, keep selperiod filter) in another BI report and it worked correctly. The only difference between the two is the addition of the AdjMonth variable in this report. Do I need to combine the AdjMonth and SelPeriod variables into one?
Thanks so much for your help!