Search code examples
powerbitableau-apipowerqueryqlikviewm

Power Bi : if Condition with multiple cases specially with date = NULL or SYSDATE


I have a table with these columns shipped_date, Promise_date

Example (consider that the current date is today's date which is "20/6/2019"):

Shipped_date        Promise_date
20/1/2019           15/1/2019
Null                19/6/2019
Null                25/6/2019

How can I make an if condition that gives output

1- if shipped_date = null and promise_date < today's date then "yes"

2- if shipped_date = null and promise_date >= today's date then "no"

i tried to write Dax code but i succeded in another condition when shipped_date have value and promise_date is not today's date

if [JC_ShippedDate] < [PromiseDate] then "Completed early"
else if [JC_ShippedDate] > [PromiseDate] then "Completed behind schedule"
else if [JC_ShippedDate] = [PromiseDate] then "Completed on time" else "open"

error is

Expression.Error: We cannot convert the value null to type Logical.
Details:
    Value=
    Type=Type

Solution

  • Not sure exactly what you are looking for but in DAX, something like this will do the trick:

    Test =
    VAR Today =
        NOW ()
    RETURN
        SWITCH (
            TRUE (),
            AND ( ISBLANK ( 'Table'[Shipped_Date] ), 'Table'[Promise_Date] < Today ), "Yes",
            AND ( ISBLANK ( 'Table'[Shipped_Date] ), 'Table'[Promise_Date] >= Today ), "No",
            'Table'[Shipped_Date] > 'Table'[Promise_Date], "x"
        )
    

    After testing on your data I get the following:

    enter image description here