Forum Discussion

Zarlot531's avatar
Zarlot531
Helper V
6 years ago
Solved

Tricky divide by "Distinct Count" problem

So below is a sample dataset to help clarify what I'm trying to do. I want to know how much we spent on, say, the "Dog" vendor divided by ALL distinct jobs, regardless of whether we spent money at the dog vendor for other jobs. 

 

So for ex, the Dog average below would be (200+200+388) / 4 (total distinct jobs, 3561, 7898, 8982, 3893) = 197 dog cost / all jobs. 

 

What Power BI seems to want to to do is give me the average of distinct jobs where and only where we had "Dog" vendor cost. 

 

So it doesn't even consider jobs 8982 or 3893. It instead wants to divide by 2 (3561 and 7898). 

 

I've tried experimenting with different DAX formulas but can't seem to get it right. @

 

  • Hi Zarlot531 ,

     

    Measure =
    VAR ave =
        SUM ( 'Table'[Amount] )
    VAR dis =
        CALCULATE ( DISTINCTCOUNT ( 'Table'[Job] ), ALL ( 'Table' ) )
    RETURN
        DIVIDE ( ave, dis )
    

    Please refer to the pbix as attached.

     

2 Replies

  • ImkeF's avatar
    ImkeF
    Community Champion

    Hi Zarlot531

    you have to remove the filter from Vendor like so:

     

    Avg across all jobs =
    VAR SumVendor =
        SUM ( Table1[Amount] )
    VAR NoOfAllJobs =
        CALCULATE ( DISTINCTCOUNT ( Table1[Job] ), ALL ( Table1[Vendor] ) )
    RETURN
        DIVIDE ( SumVendor, NoOfAllJobs )
    

     

  • v-frfei-msft's avatar
    v-frfei-msft
    Community Support

    Hi Zarlot531 ,

     

    Measure =
    VAR ave =
        SUM ( 'Table'[Amount] )
    VAR dis =
        CALCULATE ( DISTINCTCOUNT ( 'Table'[Job] ), ALL ( 'Table' ) )
    RETURN
        DIVIDE ( ave, dis )
    

    Please refer to the pbix as attached.