Forum Discussion

RichBurdick's avatar
RichBurdick
Icon for Helper I rankHelper I
6 years ago

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's avatar
    Greg_Deckler
    Icon for Community Champion rankCommunity 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's avatar
      RichBurdick
      Icon for Helper I rankHelper 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's avatar
        RichBurdick
        Icon for Helper I rankHelper 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))