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
tmitton
Frequent Visitor

Calculate Text value based on date in another column

Softball question for some of the experts out there...

 

I have a column titled "Due Date" that tells me when a specific action item will be completed by.

 

I want to calculate a "Phase" column that returns which Phase of a project that item falls under based on the date.

 

If the date is 6/30/2020 or earlier, I want the Phase column to say, "Phase 1". 

If the date is between 6/30/2020 and 9/30/2020, I want the Phase column to say, "Phase 2". 

If the date is between 10/1/20 and 12/31/20, I want the Phase column to say , "Phase 3".

If the date falls after 12/31/20, I want the Phase column to say, "N/A" or something similar. 

1 ACCEPTED SOLUTION
Greg_Deckler
Super User
Super User

@tmitton - Seems like:

Phase =
  SWITCH(TRUE(),
    [Date] <= DATE(2020,6,30),"Phase 1",
    [Date] > DATE(2020,6,30) && [Date] <= DATE(2020,9,30),"Phase 2",
    [Date] > DATE(2020,10,1) && [Date] <= DATE(2020,12,31),"Phase 3",
    "N/A"
  )

@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...

View solution in original post

5 REPLIES 5
Greg_Deckler
Super User
Super User

@tmitton - Seems like:

Phase =
  SWITCH(TRUE(),
    [Date] <= DATE(2020,6,30),"Phase 1",
    [Date] > DATE(2020,6,30) && [Date] <= DATE(2020,9,30),"Phase 2",
    [Date] > DATE(2020,10,1) && [Date] <= DATE(2020,12,31),"Phase 3",
    "N/A"
  )

@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...

This returns the following error:

tmitton_0-1598295517665.png

 

It had me remove one of the double "&" keys, and then told me that "SWTICH" is not recognized. 

 

Thanks again for any guidance you can provide.

@tmitton 

You are supposed to use @Greg_Deckler 's solution as a new column in your table in the Power BI Data Model. not in Power Query.
Select the table and 

Fowmy_0-1598297297243.png

 

________________________

Did I answer your question? Mark this post as a solution, this will help others!.

Click on the Thumbs-Up icon if you like this reply 🙂

YouTube, LinkedIn

 





Did I answer your question? Mark my post as a solution! and hit thumbs up


Subscribe and learn Power BI from these videos

Website LinkedIn PBI User Group

@tmitton 

Make sure your [Date/Time Due] is in Date format. The ERROR msg explains it.

________________________

Did I answer your question? Mark this post as a solution, this will help others!.

Click on the Thumbs-Up icon if you like this reply 🙂

YouTube, LinkedIn

Did I answer your question? Mark my post as a solution! and hit thumbs up


Subscribe and learn Power BI from these videos

Website LinkedIn PBI User Group

tmitton
Frequent Visitor

Thank you all! 

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.