Forum Discussion
Help with a DAX Formula to Return Text in a Measure
I have a table of data that looks like:
| ID | Sdate | Pdate | Ddate | Dstatus |
| 22A0B3A9 | ||||
| 6B63C304 | 9/21/2018 9:39 | 1/8/2019 8:34 | ||
| 4E1C2014 | ||||
| 29970ABD | ||||
| B59F6194 | 10/1/2018 23:01 | 10/1/2018 23:10 | 1/30/2019 10:42 | Accept |
| 76DA99FA | 11/27/2018 14:39 | 11/27/2018 14:48 | 1/8/2019 10:47 | Accept |
| 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:
| ID | Sdate | Pdate | Ddate | Dstatus | Result |
| 22A0B3A9 | |||||
| 6B63C304 | 9/21/2018 9:39 | 1/8/2019 8:34 | Pending | ||
| 4E1C2014 | 10/1/2018 23:01 | 10/1/2018 23:10 | 1/30/2019 10:42 | Accept | Accept |
| 29970ABD | 11/27/2018 14:39 | 11/27/2018 14:48 | 1/8/2019 10:47 | Accept | Pending |
| B59F6194 | 11/27/2018 14:39 | 11/27/2018 14:48 | 1/8/2019 10:47 | Pending | |
| 76DA99FA | 10/3/2018 14:40 | 10/3/2018 14:42 | 12/17/2018 11:31 | Conditional Accept | Conditional Accept |
| E7F024E0 | 1/9/2019 18:49 | 1/9/2019 18:49 | 1/10/2019 11:37 | Accept | |
| 9FA36508 | 8/22/2018 18:28 | 8/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
- rrhutch
Helper II
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",
""
)