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

Get Fabric Certified for FREE during Fabric Data Days. Don't miss your chance! Request now

Reply
GiorgosPap311
Regular Visitor

Different Values Depending On Date Hierarchy

I have a very easy (I suppose) question, but it's driving me crazy.
We have a table named "Dates" with 1 single column named "Date", let's say this one

Dates = CALENDAR("2020-01-01", "2024-01-01")

I want to create a measure and plot it on a bar chart with the following rule.

If the date hierarchy level selected is on Year level, then return 1
If the date hierarchy level selected is on Quarter level, then return 2
If the date hierarchy level selected is on Month level, then return 3
If the date hierarchy level selected is on Day level, then return 4

The reason to do so, is that if I have a way to create that, then I also have a way, using VARs, to create a bar chart that will use
PREVIOUSYEAR, PREVIOUSQUARTER, ..... dynamically depending on the level I'm currently on.

Thank you for your inputs

1 ACCEPTED SOLUTION
xifeng_L
Super User
Super User

Hi @GiorgosPap311 ,

 

You can refer to below measure.

 

xifeng_L_0-1716609204187.png

 

Measure = 
SWITCH(TRUE(),
    ISINSCOPE('Date'[Date]),    4 ,
    ISINSCOPE('Date'[Month]),   3 ,
    ISINSCOPE('Date'[Quarter]), 2 ,
    ISINSCOPE('Date'[Year]),    1
)

 

 

 

Did I answer your question? If yes, pls mark my post as a solution and appreciate your Kudos !

 

Thank you~

 

View solution in original post

2 REPLIES 2
xifeng_L
Super User
Super User

Hi @GiorgosPap311 ,

 

You can refer to below measure.

 

xifeng_L_0-1716609204187.png

 

Measure = 
SWITCH(TRUE(),
    ISINSCOPE('Date'[Date]),    4 ,
    ISINSCOPE('Date'[Month]),   3 ,
    ISINSCOPE('Date'[Quarter]), 2 ,
    ISINSCOPE('Date'[Year]),    1
)

 

 

 

Did I answer your question? If yes, pls mark my post as a solution and appreciate your Kudos !

 

Thank you~

 

I had already tried this measure, but only had 1 single column in my Dates table with the Date Hierarchy instead of using 4 different columns. I thought it should be possible only with 1 but it seems like it doesn't work the way I thought.
This works indeed, so thank you!

Helpful resources

Announcements
Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

October Power BI Update Carousel

Power BI Monthly Update - October 2025

Check out the October 2025 Power BI update to learn about new features.

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.