cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Highlighted
Frequent Visitor

DAX: Measure to Separate This Year from Last Year

Hi!

 

I have created a colum that finds tha MAX value from a table and the output would be "TY" as in"This Year".

Then, the MAX - 1 would be "LY" as in "Last Year".

 

TY_LY = IF(DB[Year]=MAX(DB[Year]);"TY";IF(VALUE(DB[Year])=VALUE(MAX(DB[Year]))-1;"LY";"2LY"))

 

 1.PNG

Since it´s a column and not a measure, when I unfilter year 2020, it stills shows me year 2019 as "LY".

¿How can I create a measure that when I filter only year 2019 and 2018, the result would be TY and LY respectively?

 

Regards

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
Highlighted
Community Support
Community Support

Re: DAX: Measure to Separate This Year from Last Year

@cam0082 

 

You may refer to the measure below.

Measure =
SWITCH (
    SELECTEDVALUE ( DB[Year] )
        - MAXX (
            ALLSELECTED ( DB[Year] ),
            DB[Year]
        ),
    0, "TY",
    -1, "LY",
    -2, "2LY"
)

 

Community Support Team _ Sam Zha
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

2 REPLIES 2
Highlighted
Super User IV
Super User IV

Re: DAX: Measure to Separate This Year from Last Year

Please see this post regarding How to Get Your Question Answered Quickly: https://community.powerbi.com/t5/Community-Blog/How-to-Get-Your-Question-Answered-Quickly/ba-p/38490


---------------------------------------

Putting square pegs in round holes since 1972.

I have a NEW book! 
DAX Cookbook from Packt
Over 120 DAX Recipes!




Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




Highlighted
Community Support
Community Support

Re: DAX: Measure to Separate This Year from Last Year

@cam0082 

 

You may refer to the measure below.

Measure =
SWITCH (
    SELECTEDVALUE ( DB[Year] )
        - MAXX (
            ALLSELECTED ( DB[Year] ),
            DB[Year]
        ),
    0, "TY",
    -1, "LY",
    -2, "2LY"
)

 

Community Support Team _ Sam Zha
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

Helpful resources

Announcements
May 2020 Community Highlights

May 2020 Community Highlights

It’s time for another PBI Community recap!

Community Blog

Community Blog

Visit our Community Blog for articles, guides, and information created by fellow community members.

Using the Community

Using the Community

Need help with the Power BI Community? Our 'Using the Community' support articles are a great place to start.

Galleries

Galleries

Looking for inspiration on how to present your data? Need instructional videos? Check out our Galleries!

Top Solution Authors