Forum Discussion
Display data for dates relative to date selected in table
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.
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!
- Anonymous4 years agoNot applicable
Anonymous again this is very difficult to debug without sample data or properly formatted code, but the Revenue variable jumps out to me as not looking quite right. You're multiplying a Filter argument by -1, when I think you're meaning to multiply the result of the CALCULATE statement by -1.
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]))
Putting this in the proper format using https://www.daxformatter.com/ makes this more clear: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] ) )