Forum Discussion
DATEDIFF When Usinf IF Argument
I am trying to wrote a DAX measurement where based on the text value of a column use these two date fields to calculate days.
I have been able to figure out the DATEDIFF part of the measurement but have been running into issues with the IF.
Here is the measurement:
CAPA Planning Days = IF(CAPATable[Record_Source] = “Audit”), (DATEDIFF(MIN(CAPATable[DATE_OPENED]), MAX(CAPAPlanFirstApproval[FirstDate]), DAY))The DateDiff works fine but could use some assistance on the IF part
13 Replies
- Greg_Deckler
Community Champion
Well, if this is a measure, you are going to need to have an aggregation like MIN or MAX around your column. I think you want something like:
CAPA Planning Days = IF( MAX(CAPATable[Record_Source]) = “Audit”, // true/false statement DATEDIFF(MIN(CAPATable[DATE_OPENED]), MAX(CAPAPlanFirstApproval[FirstDate]), DAY), //true "This is the false part" //false )- RichBurdick
Helper I
Thanks for the response but when I enter the new argument I get the following error message: Too few arguments were passed to the IF function. The minimum argument count for the function is 2.
- RichBurdick
Helper I
Maybe more information would help. I am trying to create a measure with the following criteria
If Record Source = Audit (DATEDIFF(MIN(CAPATable[DATE_OPENED]), MAX(CAPAPlanFirstApproval[FirstDate]), DAY)) and (DATEDIFF(MIN(CAPAtable[DATE_OPENED]), MAX(CorrFirstApproval[FirstDate]), DAY)) OR If Record Source = Quality Issue (DATEDIFF(MIN(CAPARequiredTable[DATE_PERFORMED], MAX(CAPATable[CAPA_PLAN_APPROVAL_ON]), DAY))