Forum Discussion

johnf's avatar
johnf
Helper I
8 years ago
Solved

Remove duplicated rows in SUM calculation

Hello,

 

I'm having some issues in trying to work out how to remove duplicate rows from a calculation.

 

I have the following dataset (highly simplified from actual)

 

KEYNAMEJOBPAYMENT
Bill|100BillElectrician100
Bill|100BillPlumber100
Jenny|200JennyElectrician200
Simon|500SimonPlumber500
Simon|500SimonGardner500

 

The issue is that the system the data imports from the payment calculation is for the total of all jobs carried out by that person. For example, Bill did work as an Electrician and a Plumber but was only paid a total of 100 for both not the summation of both job payments.

 

To attempt to filter out these duplications, I have created concatenated keys so that I should be able to filter the duplicates and sum all payments without double counting. So in the example above the total payments made to all workers should only be 800 but I can't seem to get the DAX right to remove the duplications. Can anyone assist please?

 

Thanks,

John

  • OK, try this:

     

    Measure = SUMX(SUMMARIZE(DistinctSum,[KEY],"Payment",AVERAGE(DistinctSum[PAYMENT])),[Payment])

11 Replies

    • Zubair_Muhammad's avatar
      Zubair_Muhammad
      Community Champion

      Hi johnf

       

      Another way of doing it

       

      Go to Modelling Tab >>>NEW TABLE and use this formula

       

      New Table =
      SUMMARIZE (
          TableName,
          TableName[NAME],
          "Job", CONCATENATEX ( TableName, TableName[JOB], "," ),
          "Payment", AVERAGE ( TableName[PAYMENT] )
      )
    • johnf's avatar
      johnf
      Helper I

      Thanks Greg_Deckler.

       

      I had thought along the same lines, but for some reason in trying this formula I get the "A table of multiple values was supplied where a single value was expected" error.

       

      I think this is because when passing the DISTINCT there's no condition applied to provide a boolean value for FILTER to use.

       

      As far as using Power Query to remove the duplicates, unfortunately, I need the other detail for other calculations. e.g. In this example show total paid to Plumbers.

       

       

      • Greg_Deckler's avatar
        Greg_Deckler
        Community Champion

        Not sure, I recreated your table exactly, can you post your formula?

         

  • Hello,
    How can you sum two values from two different tables? I have tried to use it as a measure but the thing is that it duplicates the rows.