Serdia
Serdia

Reputation: 4418

What would be the best way to dynamically use dates in filter function in DAX

I need to find workaround for SAMEPERIODLASTYEAR function since I was not able to make it work.

I can simply use FILTER function but having trouble how to dynamically get dates from the beginning of last year till today year back.

PrevYearPremium = CALCULATE(
                [Total Premium],FILTER(dim_Date,dim_Date[Date] >= VALUE("2018-01-01")
                && dim_Date[Date] <=VALUE("2018-04-18"))
                )

There are numerous functions like DATESBETWEEN, DATESINPERIOD, DATE. What would be the best way to dynamically use dates?

Upvotes: 0

Views: 240

Answers (1)

Mboolean
Mboolean

Reputation: 392

Try this out.. This will give you YOY compare..

CALCULATE([Total Premium]
                        ,DATESBETWEEN('Dim_Date'[Date]
                                    ,FIRSTDATE('Dim_Date'[Date])
                                    ,LASTDATE('Dim_Date'[Date]))
                        ,DATEADD('Dim_Date'[Date],-1,YEAR)

Upvotes: 1

Related Questions