Suneth
Suneth

Reputation: 209

How to get the last year value based on filter selection?

I want to get the last year value-based no filter value I selected. For example, if I selected 2019 on the filter, I want to get 2018 values (See picture below). I have a formula, but it will give me blank, Not sure whats wrong with. Can anybody please help me to get this? (Right now I am getting nothing, just blank)

Last Year = 
VAR LastYear = 
CALCULATE(
    [Line Amount (Formatted)], 
    FILTER(
        'Calendar - Fiscal Date',
        'Calendar - Fiscal Date'[FiscalYr Year Number] = 
                SELECTEDVALUE('Calendar - Fiscal Date'[FiscalYr Year Number]) -1
    )
)

return LastYear

My Data enter image description here

Thank you so much

Upvotes: 1

Views: 4410

Answers (1)

mkRabbani
mkRabbani

Reputation: 16908

Did you checked DAX function PREVIOUSYER? You can check more details Here

You can also try this below adjusted measure-

Last Year = 

VAR LastYear = SELECTEDVALUE('Calendar - Fiscal Date'[FiscalYr Year Number]) -1

VAR LastYearValue = 
CALCULATE(
    [Line Amount (Formatted)], 
    FILTER(
        ALL('Calendar - Fiscal Date'),
        'Calendar - Fiscal Date'[FiscalYr Year Number] = LastYear 
                
    )
)

return LastYearValue

Upvotes: 1

Related Questions