Forum Discussion

vega's avatar
vega
Icon for Resolver III rankResolver III
8 years ago
Solved

Date Crossfilter If Statement

Hello,  I have the following formula and it is throwing an error and I am not sure why VAR test = IF( ISCROSSFILTERED(Dates[Date]), Dates[Date], DATESBETWEEN(Dates[Date], MIN(Dates[Dat...
  • vega's avatar
    vega
    8 years ago

    The output visual was supposed to contain no date selections and no dates on the rows and columns. This is why the formula proved to be difficult. I was able to get the formula to work using a slightly different approach. I'll leave the formula here in case anyone in the future faces a similar problem.

     

    Current Actual + Forecast Room Revenue:= 
    VAR maxdate = MAX(Dates[Date])
    VAR R3M =
    CALCULATE(
    	[Actual + Forecast Room Revenue],
    	ALL(Dates[Date]),
    	DATESBETWEEN(
    		Dates[Date],
    		DATE(YEAR(maxdate), MONTH(maxdate)-2, DAY(maxdate)),
    		maxdate
    	)
    )
    VAR R12M =
    CALCULATE(
    	[Actual + Forecast Room Revenue],
    	ALL(Dates[Date]),
    	DATESBETWEEN(
    		Dates[Date],
    		DATE(YEAR(maxdate), MONTH(maxdate)-11, DAY(maxdate)),
    		maxdate
    	)
    )
    RETURN
    
    SWITCH(
    	SELECTEDVALUE(Periods[Period]),
    	"YTD", 
    		IF(
    			ISCROSSFILTERED(Dates[Date]), 
    			TOTALYTD([Actual + Forecast Room Revenue],Dates[Date]), 
    			TOTALYTD([Actual + Forecast Room Revenue], DATESBETWEEN(Dates[Date], MIN(Dates[Date]), TODAY()-1))
    		),
    	"MTD", 
    		IF(
    			ISCROSSFILTERED(Dates[Date]),
    			TOTALMTD([Actual + Forecast Room Revenue], Dates[Date]),
    			TOTALMTD([Actual + Forecast Room Revenue], DATESBETWEEN(Dates[Date], MIN(Dates[Date]), TODAY()-1))
    		),
    	"QTD", 
    		IF(
    			ISCROSSFILTERED(Dates[Date]), 
    			TOTALQTD([Actual + Forecast Room Revenue],Dates[Date]), 
    			TOTALQTD([Actual + Forecast Room Revenue], DATESBETWEEN(Dates[Date], MIN(Dates[Date]), TODAY()-1))
    		),
    	"R3M", R3M,
    	"R12M", R12M,
    	[Actual + Forecast Room Revenue]
    )



    As you can see, I just did an if statement that will either give me the time intelligence function for all dates if the dates are filtered or the time intelligence function for yesterday if the dates are not filtered. I realize that this is not a typical use case, it was just a special request from my supervisor.

     

    Thank you all for all of your help, I couldn't have gotten to the solution without you all. Thank you!