Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

July 28 - August 9 | Final Round of the Power BI Dataviz World Championships. This is your chance. Learn more

Reply
_Aleksa_
Helper II
Helper II

Dynamic SWITCH TIME Statement

Hello,

 

I need help making the second part of the statement below dynamic so that it reflects current year appropriately as time goes by.

 

Tiers =
SWITCH (
    TRUE (),
    'Weekly Data'[Injury_Dte] = year(today()-3), 'CY'
                'Weekly Data'[Injury_Dte] = year(today()-3)-1, 'PY 1'
     'Weekly Data'[Injury_Dte]) = year(today()-3)-2, 'PY 2'
                'Weekly Data'[Injury_Dte] = year(today()-3)-3 , 'PY 3'
                'Weekly Data'[Injury_Dte] = year(today()-3)-4 , 'PY 4'
                'Weekly Data'[Injury_Dte] = year(today()-3)-5 , 'PY 5'
">PY6"
)

Thank you in advance!!
1 ACCEPTED SOLUTION

Hi,

 

Please try this calculated column:

Tiers = 
IF (
    YEAR ( 'Table'[Date] )
        = YEAR ( TODAY () - 3 ),
    "CY",
    "PY"
        & DATEDIFF ( 'Table'[Date], TODAY () - 3, YEAR )
)

The result shows:

1.PNG

See my attached pbix file.

 

Best Regards,

Giotto

View solution in original post

4 REPLIES 4
Anonymous
Not applicable

@_Aleksa_ ,

 

You can try below measure
 
CCYR =

Var _date_ = MAX('Weekly Data'[Injury_Dte])
var _diff = DATEDIFF(_date_,TODAY(),YEAR)
RETURN
SWITCH(
TRUE(),
_diff = 0 , "CY",
_diff > 0 , CONCATENATE("PY",FORMAT(_diff,"##"))
)

 

1.jpg

 

Regards,
Harsh Nathani

Did I answer your question? Mark my post as a solution! Appreciate with a Kudos!! (Click the Thumbs Up Button)

amitchandak
Super User
Super User

The information you have provided is not making the problem clear to me. Can you please explain with an example.

Appreciate your Kudos.

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

I am trying to avoid hardcoding any years like in the example below.

 I want to put a formula instead of an actual year which will provide a respective yearso that I don't have to updates manually the years in the statement every year.

 

Tiers =
SWITCH (
    TRUE (),
    'Weekly Data'[Injury_Dte] = 2020, 'CY'
                'Weekly Data'[Injury_Dte] = 2019, 'PY 1'
     'Weekly Data'[Injury_Dte]) = 2018, 'PY 2'
                .....
">PY6"

)

Hi,

 

Please try this calculated column:

Tiers = 
IF (
    YEAR ( 'Table'[Date] )
        = YEAR ( TODAY () - 3 ),
    "CY",
    "PY"
        & DATEDIFF ( 'Table'[Date], TODAY () - 3, YEAR )
)

The result shows:

1.PNG

See my attached pbix file.

 

Best Regards,

Giotto

Helpful resources

Announcements
FabCon and SQLCon Barcelona 2026

FabCon & SQLCon – Barcelona 2026

Join us in Barcelona for FabCon and SQLCon, the Fabric, Power BI, SQL, and AI community event. Save €200 with code FABCMTY200.

Fabric Community Sticker Design Challenge Barcelona Carousel

Fabric Community Sticker Challenge - Barcelona 2026

If you love stickers, then you will definitely want to check out our community sticker challenge, Barcelona edition!

July Power BI Update Carousel

Power BI Monthly Update - July 2026

Check out the July 2026 Power BI update to learn about new features.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.