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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
matts29
Frequent Visitor

if/case statement

Hi 

 

Can someone please help.

 

I would like to write a logic in Power BI stating

 

If reviewdate is between today and the next 3 years then 1

If reviewdate is between today and the next 6 months then 2

If reviewdate is between today and the next 18 months then 3

 

all within the same column?

 

Thank you

1 ACCEPTED SOLUTION
FreemanZ
Super User
Super User

hi @matts29 ,

 

not sure if i fully get you, supposing you have a data table:

reviewdate
2/7/2024
2/8/2024
8/8/2024
8/9/2024
8/8/2025
8/9/2025
2/8/2027
2/9/2027

 

try to add a calculated column like:

Column = 
SWITCH(
    TRUE(),
    data[reviewdate]<=EDATE(TODAY(), 6), 2,
    data[reviewdate]<=EDATE(TODAY(), 18), 3,
    data[reviewdate]<=EDATE(TODAY(), 36), 1,
    0
)

 

it worked like:

FreemanZ_0-1707386867982.png

 

View solution in original post

2 REPLIES 2
FreemanZ
Super User
Super User

hi @matts29 ,

 

not sure if i fully get you, supposing you have a data table:

reviewdate
2/7/2024
2/8/2024
8/8/2024
8/9/2024
8/8/2025
8/9/2025
2/8/2027
2/9/2027

 

try to add a calculated column like:

Column = 
SWITCH(
    TRUE(),
    data[reviewdate]<=EDATE(TODAY(), 6), 2,
    data[reviewdate]<=EDATE(TODAY(), 18), 3,
    data[reviewdate]<=EDATE(TODAY(), 36), 1,
    0
)

 

it worked like:

FreemanZ_0-1707386867982.png

 

Thanks thats brilliant! have  a good day 🙂

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

November Power BI Update Carousel

Power BI Monthly Update - November 2025

Check out the November 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.