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
jibran
Helper II
Helper II

IF statement not working

Hi All,

I am struggling to make work IF statement. 

I want to use IF statement where the value equals to the some value then show me the date value, else NULL value.

 

Example Ext End Contract = IF('Extended Contract'[VEHICLESTATUS] = "Extended Contract",LASTDATE('Extende
d Contract'[Ext End Contract]),"Jibran")

Error that I receive is "Expressions that yield variant data-type cannot be used to define calculated columns."

Table.JPG

 

 

 

 

 

 

Many Thanks

 

1 ACCEPTED SOLUTION

@jibran

 

Please try with following formula.

 

Example Ext End Contract =
IF (
    'Extended Contract'[VEHICLESTATUS] = "Extended Contract",
    FORMAT (
        CALCULATE (
            LASTDATE ( 'Extended Contract'[Ext End Contract] ),
            ALLEXCEPT (
                'Extended Contract',
                'Extended Contract'[CUSTOMERNAME],
                'Extended Contract'[REGISTRATIONNO],
                'Extended Contract'[Fleetware Contract ID]
            )
        ),
        ""
    ),
    "Jibran"
)

 

Best Regards,
Herbert

View solution in original post

4 REPLIES 4

Your result cannot mix data types between Date and Text. If your alternate result is "Jibran" (Text), the first result must also be Text. You can use FORMAT() to convert the date value to text: FORMAT(LASTDATE( [...] ),"Text")

Hi,

 

I applied the Fomat function and pass the desired string to the function as shown below, but it is displaying duplicate data.

It looks like with the inclusion of Format function the last date fuction is not working any more

 

Dax query is

 

Example Ext End Contract = IF('Extended Contract'[VEHICLESTATUS] = "Extended Contract",FORMAT(LASTDATE('Extended Contract'[Ext End Contract]), "ddd dd/MM/YYYY"),"No Date")

 

duplicate data.JPG

My desired result has to be something like this

 

desired result.JPG

 

 

Many Thanks 

 

 

Hi @jibran

 

I think you can achieve what you want with a measure rather than a calculated column

 

Extended Last Date =CALCULATE( LASTDATE(ExtendedContract[Ext End Contract]), 
ExtendedContract[VEHICLE STATUS]="Extended Contract")

 

Extended End Date (Last Date).PNG

 

 

@jibran

 

Please try with following formula.

 

Example Ext End Contract =
IF (
    'Extended Contract'[VEHICLESTATUS] = "Extended Contract",
    FORMAT (
        CALCULATE (
            LASTDATE ( 'Extended Contract'[Ext End Contract] ),
            ALLEXCEPT (
                'Extended Contract',
                'Extended Contract'[CUSTOMERNAME],
                'Extended Contract'[REGISTRATIONNO],
                'Extended Contract'[Fleetware Contract ID]
            )
        ),
        ""
    ),
    "Jibran"
)

 

Best Regards,
Herbert

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.

Top Solution Authors