Forum Discussion

rrhutch's avatar
rrhutch
Icon for Helper II rankHelper II
7 years ago
Solved

Help with a DAX Formula to Return Text in a Measure

I have a table of data that looks like:

 

IDSdatePdateDdateDstatus
22A0B3A9    
6B63C3049/21/2018 9:391/8/2019 8:34  
4E1C2014    
29970ABD    
B59F619410/1/2018 23:0110/1/2018 23:101/30/2019 10:42Accept
76DA99FA11/27/2018 14:3911/27/2018 14:481/8/2019 10:47Accept
E7F024E0    

 

I am trying to add a Results Column based on a slicer date value (in this case the date slice value is 12/18/18) that would make the data look like:

 

IDSdatePdateDdateDstatusResult
22A0B3A9     
6B63C3049/21/2018 9:391/8/2019 8:34  Pending
4E1C201410/1/2018 23:0110/1/2018 23:101/30/2019 10:42AcceptAccept
29970ABD11/27/2018 14:3911/27/2018 14:481/8/2019 10:47AcceptPending
B59F619411/27/2018 14:3911/27/2018 14:481/8/2019 10:47 Pending
76DA99FA10/3/2018 14:4010/3/2018 14:4212/17/2018 11:31Conditional AcceptConditional Accept
E7F024E01/9/2019 18:491/9/2019 18:491/10/2019 11:37Accept 
9FA365088/22/2018 18:288/22/2018 18:33  Pending

 

If I was doing this in Excel, my formula would be =IF(AND([Ddate]<>"",[Ddate]<=12/18/18),[Dstatus],IF(AND([Pdate]]<>"",[Pdate]<=12/18/18),"Pending",IF(AND([Sdate]<>"",[Sdate]<=12/18/18),"Pending","")))

 

In DAX I am able build the logic in the proper DAX format, but the return value I am getting in the Measure is a not a text value. I actually get an error because it is says it is comparing Date types to Text types.

 

While this isn't the full DAX forumla, it is the one I am testing for at least the first step in the comparison:

 

St =
IF (
    AND (
        ( MIN ( TableA[Ddate] ) <> "" ),
        ( MIN ( TableA[Ddate] ) <= TableA[SlicerDateSelected] )
    ),
    MINA ( SlateAppData[Dstatus] ),
    ""
)

 

[SlicerDateSelected] is just the Max value from a slicer on a date table I have created.

 

What I am missing?

  • Figured my problem out. It wasn't an issue with the getting the result as a text value but my problem was the comparison was trying to compare date and text types. Instead I used the following to achieve what I needed. I was comparing a Date field to "" to determine if not blank. Everything worked fine once I used the BLANK() function instead in the comparison.

     

     

    St =
    SWITCH (
        TRUE (),
        AND (
            MINA ( TableA[Ddate] ) <> BLANK (),
            MINA ( TableA[Ddate] ) <= [SlicerDateSelected]
        )MINA ( TableA[Dstatus] ),
        AND (
            MINA ( TableA[Pdate] ) <> BLANK (),
            MINA ( TableA[Pdate] ) <= [SlicerDateSelected]
        )"Pending",
        AND (
            MINA ( TableA[Sdate] ) <> BLANK (),
            MINA ( TableA[Sdate] ) <= [SlicerDateSelected]
        )"Pending",
        ""
    )

     

1 Reply

  • Figured my problem out. It wasn't an issue with the getting the result as a text value but my problem was the comparison was trying to compare date and text types. Instead I used the following to achieve what I needed. I was comparing a Date field to "" to determine if not blank. Everything worked fine once I used the BLANK() function instead in the comparison.

     

     

    St =
    SWITCH (
        TRUE (),
        AND (
            MINA ( TableA[Ddate] ) <> BLANK (),
            MINA ( TableA[Ddate] ) <= [SlicerDateSelected]
        )MINA ( TableA[Dstatus] ),
        AND (
            MINA ( TableA[Pdate] ) <> BLANK (),
            MINA ( TableA[Pdate] ) <= [SlicerDateSelected]
        )"Pending",
        AND (
            MINA ( TableA[Sdate] ) <> BLANK (),
            MINA ( TableA[Sdate] ) <= [SlicerDateSelected]
        )"Pending",
        ""
    )