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
harshagraj
Post Partisan
Post Partisan

Calculated column for weeks with condition

Hi all please help me to create a calculated column to achieve this with color.

If Finish Date < 5-10 weeks than Milestone then "Green"
If Finish Date < 2-5 weeks than Milestone then "Yellow"
If Finish Date >= than Milestone then "Red"

"


PS: Both are date columns with hierarchy.

1 ACCEPTED SOLUTION
az38
Community Champion
Community Champion

Hi @harshagraj 

your conditions is completely unclear and not consistent, but i can suggest smth like this

Column = 
var _datediff = DATEDIFF([Finish Date],[Milestone], WEEK)
RETURN
SWITCH(TRUE(),
_datediff > 5 && _datediff < 10, "Green", 
_datediff > 2 && _datediff < 5, "Yellow", 
_datediff <= 0, "Red",
BLANK()
)

 


do not hesitate to give a kudo to useful posts and mark solutions as solution
LinkedIn

View solution in original post

2 REPLIES 2
az38
Community Champion
Community Champion

Hi @harshagraj 

your conditions is completely unclear and not consistent, but i can suggest smth like this

Column = 
var _datediff = DATEDIFF([Finish Date],[Milestone], WEEK)
RETURN
SWITCH(TRUE(),
_datediff > 5 && _datediff < 10, "Green", 
_datediff > 2 && _datediff < 5, "Yellow", 
_datediff <= 0, "Red",
BLANK()
)

 


do not hesitate to give a kudo to useful posts and mark solutions as solution
LinkedIn

Hi @az38  thank you so much. This is working perfectly.

Helpful resources

Announcements
November Power BI Update Carousel

Power BI Monthly Update - November 2025

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

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!

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.

Top Solution Authors
Top Kudoed Authors