Forum Discussion

android1's avatar
android1
Post Patron
10 years ago

IF OR when using COUNTROWS

Hi,

 

I'm need to modify the measure On Time = COUNTROWS(FILTER(OTIF,[ShiftInTime]=[TimeFrom]*[targetperc OT])) to also

COUNTROWS if [ShiftInTime]<> [TimeFrom]

 

Thinking IF OR but don't know how.

5 Replies

  • chrisu's avatar
    chrisu
    Responsive Resident

    Would it work to add an OR (||) within the filter?  It should count the rows where either of your tests are true.  

     

    On Time = COUNTROWS(FILTER(OTIF, [ShiftInTime]=[TimeFrom]*[targetperc OT] || [ShiftInTime]<> [TimeFrom]))

  • v-caliao-msft's avatar
    v-caliao-msft
    Microsoft Employee

    android1

    For CountRows, I don’t think it would work with the logical function, but we could use the logical function within the filter function.

     

    For the situation, if you would like to have both conditions work, we could write the formula in the following format: 

    On Time = COUNTROWS(

                     FILTER(

                           OTIF,

                           And([ShiftInTime]=[TimeFrom]*[ta​rgetperc OT], [ShiftInTime]<> [TimeFrom]

                                   )

                                

                              )

     

    This works if both [TimeFrom]*[ta​rgetperc OT]  And [ShiftInTime]<> [TimeFrom] are true; 

    The formula would be OK to write in the following way: 

    On Time = COUNTROWS(

                   FILTER(

                     FILTER(

                           OTIF,

                           [ShiftInTime]=[TimeFrom]*[ta​rgetperc OT]

                                  ),

                      [ShiftInTime]<> [TimeFrom]

                                )

                     

     

                             

    If you would like to use the Or function, use it in the following way: 

    On Time = COUNTROWS(

                     FILTER(

                           OTIF,

                           OR([ShiftInTime]=[TimeFrom]*[ta​rgetperc OT], [ShiftInTime]<> [TimeFrom]

                                   )

                                

                              )

     

    The value is TRUE if any of the two arguments is TRUE; the value is FALSE if both the arguments are FALSE. 

    Adding the OR AND function reference: 

    OR Function (DAX)

    AND Function (DAX)

     

    Any further assistance needed, please post back.

     

    Regards,

    Charlie Liao

      • v-caliao-msft's avatar
        v-caliao-msft
        Microsoft Employee

        I checked your data, the reason why the OT %won’t work, is because your measure having issue calculating OT(+ 15 -15):

         

        OT(+15-15) =

        COUNTROWS ( FILTER ( OTIF, OTIF[Punctuality] = "On Time" ) )

         

        [On time] is a measure,  and should be write in a format of [On Time], which is the only measure that uses the OT % column; and OTIF[Punctuality] is in text type, when comparing those two values, it will generating errors under the visuals.

        I think you might need to re-consider how to calculate the OT(+15-15) value here.