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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
harshagraj
Post Partisan
Post Partisan

Calculated column for weeks with condition

Hello everyone please help me create a calculated column to achieve this with color.

If the end date < 5-10 weeks you milestone then "green"
If the end date < 2-5 weeks that the milestone then "yellow"
If the end date > that milestone then "Red"

"


PS: Both are date columns with hierarchy.

2 REPLIES 2
mahoneypat
Employee
Employee

Here's one way to do it.  This measure evaluates the weeks between milestone and enddate, and returns a color value as text.  You can then use that measure in conditional formatting for the background of any of your columns.  Choose Field Value option and pick this measure.

 

 
MilestoneColor = var weeksaway = DATEDIFF(MIN(Milestones[EndDate]), MIN(Milestones[Milestone]), WEEK)
var colorcode = SWITCH(TRUE(), weeksaway<0, "Red", weeksaway<5, "Yellow", "Green")
return colorcode
 
Here is what it will look like
MilestoneColor.png
 
If this works for you, please mark it as the solution.  Kudos are appreciated too.
Regards,
Pat
 




Did I answer your question? Mark my post as a solution! Kudos are also appreciated!

To learn more about Power BI, follow me on Twitter or subscribe on YouTube.


@mahoneypa HoosierBI on YouTube


amitchandak
Super User
Super User

@harshagraj 

Create a column date diff

Diff = datediff([end date],[milestone],day])/7

 

Create a color measure

Color Date = if(FIRSTNONBLANK([Diff ],0) <5,"green",if(FIRSTNONBLANK([Diff ],0) <3,"yellow","red"))

 

You can use the same in Conditional formatting. After using "fields".

 

https://radacad.com/dax-and-conditional-formatting-better-together-find-the-biggest-and-smallest-num...

https://docs.microsoft.com/en-us/power-bi/desktop-conditional-table-formatting#color-by-color-values

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.