Forum Discussion

masplin's avatar
masplin
Icon for Impactful Individual rankImpactful Individual
7 years ago
Solved

Scratching my head over AVERAGEX

I have a bunch of engineers who get assigned work for each day and I have come up with a scoring system for how well each is utilissed on a particular day. What i woudl like the is overall average score for each day for all engineers, but getting something differnet that is an average of something, but can't work out what. Each engineer may have several calls assigned for one day so the score is based on their totla for the day.

 

Eng Day Score = 
VAR
NewinHours=CALCULATE([Labour Hours],'Install Report'[CALL_TYPE]="NEWIN")
                              
                            
RETURN
         
          AVERAGEX(
                     SUMMARIZE(
                              'Install Report',
                              DateTable[Day],
                              'Install Report'[ENGINEER]
                              ),
                    IF(
                        [Newin Jobs]>2,                        
                        5,
                        IF(
                            [Newin Jobs]=2 ||
                            AND([Newin Jobs]=1,NewinHours>=7),
                            4,
                            IF(
                                [Newin Jobs]=1 && NewinHours<7  && [Labour Hours]>=6,
                                3,
                                IF(
                                    [Labour Hours]>4,
                                    2,
                                    1
                                ))))) 

This is the result

 

 

So score for each engineer is right based on my if statement, but total should clearly be 2.5. I tried wrapping the measure in another AVERAGEX summarised jut by day but that makes no differnece.  Any pointers appreciated?

 

Mike

  • Hi masplin 

    You may create a condition measure.Then get the Eng Day Score with it.

    Condition =
    VAR NewinHours =
        CALCULATE ( [Labour Hours], 'Install Report'[CALL_TYPE] = "NEWIN" )
    RETURN
        IF (
            [Newin Jobs] > 2,
            5,
            IF (
                [Newin Jobs] = 2
                    || AND ( [Newin Jobs] = 1, NewinHours >= 7 ),
                4,
                IF (
                    [Newin Jobs] = 1
                        && NewinHours < 7
                        && [Labour Hours] >= 6,
                    3,
                    IF ( [Labour Hours] > 4, 2, IF ( [Labour Hours] > 0, 1, 0 ) )
                )
            )
        )
    
    Eng Day Score = 
    VAR
    NewinHours=CALCULATE([Labour Hours],'Install Report'[CALL_TYPE]="NEWIN")
                                  
                                
    RETURN
          
              AVERAGEX(
                         SUMMARIZE(
                                  'Install Report',
                                  DateTable[Day],
                                  'Install Report'[ENGINEER]
                                  ),
                    [Condition]
                    )

    Regards,

7 Replies

  • v-cherch-msft's avatar
    v-cherch-msft
    Icon for Microsoft Employee rankMicrosoft Employee

    Hi masplin 

    It seems you may use ALL function: ALL(DateTable[Day]) to ignore the filters by date.Reference:https://www.sqlbi.com/articles/managing-all-functions-in-dax-all-allselected-allnoblankrow-allexcept/

    If you need further help,please share some sample data and expected output which would be helpful to provide an accurate solution.You can also upload the .pbix file to OneDrive and post the link here. Do mask sensitive data before uploading.

    Regards,

    • masplin's avatar
      masplin
      Icon for Impactful Individual rankImpactful Individual

      Hi Cherie. As suggested have attached a sample file so any help on this apprecaited as same syntax seems to work fine on other calculations

       

      Mike

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

    To debug, I would  try tp split it into 2 (or even 3) measures : 

    1) calculate the score

    2) do an averagex over that.

     

    sometimes this way it is easier to understand what is going on with contexts etc....

    • masplin's avatar
      masplin
      Icon for Impactful Individual rankImpactful Individual

      The whole point is to work out the calculation first for each enginner for each day and then secondly for all engineers per day so not sure how ALL(day) is going to help.

       

      Here is a link to simplified pbix that just has 2 days in it Engineer Utilisation

       

      To Pauls point I changed the calcuation to SUMX which I think is only way to break the measure (since calcuation has ot be done for all CALL_NUMBERS on that day for that engineer) and you can see that this is adding up all wrong in the total in the bottom table.

       

      What is odd is some combinations of engineers on some days seem fine e.g. top table, but add in Adma and goes wrong. 

       

      Change the top table to 23rd and calculation goes wrong gain. Perflexed

       

      Thnaks for any help

      Mike

      • v-cherch-msft's avatar
        v-cherch-msft
        Icon for Microsoft Employee rankMicrosoft Employee

        Hi masplin 

        You may create a condition measure.Then get the Eng Day Score with it.

        Condition =
        VAR NewinHours =
            CALCULATE ( [Labour Hours], 'Install Report'[CALL_TYPE] = "NEWIN" )
        RETURN
            IF (
                [Newin Jobs] > 2,
                5,
                IF (
                    [Newin Jobs] = 2
                        || AND ( [Newin Jobs] = 1, NewinHours >= 7 ),
                    4,
                    IF (
                        [Newin Jobs] = 1
                            && NewinHours < 7
                            && [Labour Hours] >= 6,
                        3,
                        IF ( [Labour Hours] > 4, 2, IF ( [Labour Hours] > 0, 1, 0 ) )
                    )
                )
            )
        
        Eng Day Score = 
        VAR
        NewinHours=CALCULATE([Labour Hours],'Install Report'[CALL_TYPE]="NEWIN")
                                      
                                    
        RETURN
              
                  AVERAGEX(
                             SUMMARIZE(
                                      'Install Report',
                                      DateTable[Day],
                                      'Install Report'[ENGINEER]
                                      ),
                        [Condition]
                        )

        Regards,