Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
3 years ago
Solved

DAX IF OR Measure not working based on criteria

Hi Experts

 

I cannot work out whats wrong with the following Measure

 

Criteria

If Worktype = RM and MEUCOMPLIANCEIMPACT = 1  then VAR _A

if Worktype = REMST and MEUCOMPLIANCEIMPACT = 0 the VAR _B 

 

Measure

 

Remedial Tasks =
VAR _A = CALCULATE([Count],          
                FILTER(USVF_WO_22_12_22,USVF_WO_22_12_22[WORKTYPE] = "RW" && USVF_WO_22_12_22[MEUCOMPLIANCEIMPACT] = 1),
                       USVF_WO_22_12_22[STATUS] <> "CAN",
                       ALL(DimDate[Date]))

VAR _B = CALCULATE([Count],          
                FILTER(USVF_WO_22_12_22,USVF_WO_22_12_22[WORKTYPE] = "REMST"),
                       USVF_WO_22_12_22[STATUS] <> "CAN",
                       ALL(DimDate[Date]))
Return
    IF(OR(_A,_B),0)+0      

 

Sample Data

CountWorktypeStatusMEUCOMPLIANCEIMPACT
1RWPPM0
1RWPPM0
1RWPPM0
1RWPPM0
1REMSTPPM0
1REMSTPPM0
1REMSTPPM0
1REMSTPPM0
  • Anonymous 

     

    You haven't given the Criteria to the IF statement. 

     

    Since you have more than 1 criteria, it may be easier to use a SWITCH:

     

    keep the top part of your measure, but change the RETURN to:

    RETURN

    SWITCH( TRUE(),

    SELECTEDVALUE(Table[Worktype] )= "RM" && SELECTEDVALUE([MEUCOMPLIANCEIMPACT] )= 1  ,  _A, 

    SELECTEDVALUE(Table[Worktype] )= "RMST" && SELECTEDVALUE([MEUCOMPLIANCEIMPACT])  = 0 , _B 

    )

     

    Since it's a measure, you'll need to aggregate the Worktype and MEUCOMPLIANCEIMPACT columns in some way. I chose SELECTEDVALUE, but you could use MAX or SUM depending on how you want it to work. 

7 Replies

  • AllisonKennedy's avatar
    AllisonKennedy
    Icon for Community Champion rankCommunity Champion

    Anonymous 

     

    You haven't given the Criteria to the IF statement. 

     

    Since you have more than 1 criteria, it may be easier to use a SWITCH:

     

    keep the top part of your measure, but change the RETURN to:

    RETURN

    SWITCH( TRUE(),

    SELECTEDVALUE(Table[Worktype] )= "RM" && SELECTEDVALUE([MEUCOMPLIANCEIMPACT] )= 1  ,  _A, 

    SELECTEDVALUE(Table[Worktype] )= "RMST" && SELECTEDVALUE([MEUCOMPLIANCEIMPACT])  = 0 , _B 

    )

     

    Since it's a measure, you'll need to aggregate the Worktype and MEUCOMPLIANCEIMPACT columns in some way. I chose SELECTEDVALUE, but you could use MAX or SUM depending on how you want it to work. 

    • Anonymous's avatar
      Anonymous
      Not applicable

      Hi Allison - firstly thanks for looking at the question but i am getting a blank as th end result when a value is expected

      fUll measure

      Remedial Tasks =
      VAR _A = CALCULATE([Count],          
                      FILTER(USVF_WO_22_12_22,USVF_WO_22_12_22[WORKTYPE] = "RW" && USVF_WO_22_12_22[MEUCOMPLIANCEIMPACT] = 1),
                             USVF_WO_22_12_22[STATUS] <> "CAN",
                             ALL(DimDate[Date]))

      VAR _B = CALCULATE([Count],          
                      FILTER(USVF_WO_22_12_22,USVF_WO_22_12_22[WORKTYPE] = "REMST"),
                             USVF_WO_22_12_22[STATUS] <> "CAN",
                             ALL(DimDate[Date]))
      RETURN

      SWITCH( TRUE(),

      SELECTEDVALUE(USVF_WO_22_12_22[WORKTYPE] )= "RM" && SELECTEDVALUE(USVF_WO_22_12_22[MEUCOMPLIANCEIMPACT] )= 1  ,  _A,

      SELECTEDVALUE(USVF_WO_22_12_22[WORKTYPE] )= "RMST" && SELECTEDVALUE(USVF_WO_22_12_22[MEUCOMPLIANCEIMPACT])  = 0 , _B

      )    
      • AllisonKennedy's avatar
        AllisonKennedy
        Icon for Community Champion rankCommunity Champion

        Anonymous  What visual context are you trying to use this in? Try changing the SELECTEDVALUE to max and see if that gives you a result, then you need to understand what that is doing as it may not be what you want (which is why I chose SELECTEDVALUE as I find it better to give blank than an incorrect / misleading result). 

         

        You need to make sure that you're using WorkTYPE and MEUCOMPLINCEIMPACT columns in the visual where you're using this measure. 

         

        If that still doesn't help, please provide more sample data and include the Date column and any relationships. 

    • Anonymous's avatar
      Anonymous
      Not applicable
      Volume Variance_final =
      sumx(SUMMARIZE(ATC,ATC[top_level_account],ATC[customer_segment]),
      SUMX(VALUES(ATC[material_style1]),
       if([Price per Unit_CY]=0||[Price per Unit_PY]=0,[Sales Variance],[Quantity_variance]*[Price per Unit_PY]))
      )
       
      if statement not working please help