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
Brett007
Helper III
Helper III

Layered If Statement with a mix of Dates and Text

I made a custom column similar to this;


Text or Date = 
If(ISBLANK(Table1[Status], Table1[Step Status],
If(Table1[Status] = "In Progress", Table1[Step Due Date].[Date],

If(Table1[Status] = "C=Complete", Table1[Step Actual Date].[Date],

If(Table1[Status] = "Not Required", "Not Required",
Blank())))))

I receive a error:

Expressions that yield variant data-type cannot be used to define calculated columns. 

 

I have the column set to text.  I tried MIN( around the dates as well. 

 

Any ideas of what to try next?

Thanks

1 ACCEPTED SOLUTION
AlexisOlson
Super User
Super User

First, you need to close your ISBLANK parentheses.

 

Addressing your actual question, you can use the FORMAT function to convert date to whatever format you'd like. For example, FORMAT ( Table1[DueDate], "mm/dd/yy" ) or FORMAT ( Table1[DueDate], "yyyy-mm-dd" ).

 

This is a good case to use a SWITCH function too.

Text or Date =
SWITCH (
    Table1[Status],
    BLANK (), Table1[Step Status],
    "In Progress", FORMAT ( Table1[Step Due Date], "yyyy-mm-dd" ),
    "C=Complete", FORMAT ( Table1[Step Actual Date], "yyyy-mm-dd" ),
    "Not Required", "Not Required",
    BLANK ()
)

View solution in original post

2 REPLIES 2
Jihwan_Kim
Super User
Super User

Hi, @Brett007 

Please try something like below.

 

Text or Date = 
If(ISBLANK(Table1[Status], Table1[Step Status],
If(Table1[Status] = "In Progress", format(Table1[Step Due Date].[Date], "ddmmmmyyyy"),

If(Table1[Status] = "C=Complete", format(Table1[Step Actual Date].[Date], "ddmmmmyyyy"),

If(Table1[Status] = "Not Required", "Not Required",
Blank())))))

 

Hi, My name is Jihwan Kim.

 

If this post helps, then please consider accept it as the solution to help other members find it faster, and give a big thumbs up.

 

Linkedin: linkedin.com/in/jihwankim1975/

Twitter: twitter.com/Jihwan_JHKIM

If this post helps, then please consider accepting it as the solution to help other members find it faster, and give a big thumbs up.


Go to My LinkedIn Page


AlexisOlson
Super User
Super User

First, you need to close your ISBLANK parentheses.

 

Addressing your actual question, you can use the FORMAT function to convert date to whatever format you'd like. For example, FORMAT ( Table1[DueDate], "mm/dd/yy" ) or FORMAT ( Table1[DueDate], "yyyy-mm-dd" ).

 

This is a good case to use a SWITCH function too.

Text or Date =
SWITCH (
    Table1[Status],
    BLANK (), Table1[Step Status],
    "In Progress", FORMAT ( Table1[Step Due Date], "yyyy-mm-dd" ),
    "C=Complete", FORMAT ( Table1[Step Actual Date], "yyyy-mm-dd" ),
    "Not Required", "Not Required",
    BLANK ()
)

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.