Forum Discussion

Ericwhv's avatar
Ericwhv
Helper II
5 years ago
Solved

Sumx with Distinct Value

Hi Everyone

🙂

not sure if anyone could help me

currently, i am working on the total weight of below table

but you can see some of the File Ref is duplicate, i just need the weight of Distinct File Ref

so, i wrote...

DistinctTotalWeight = SUMX(DISTINCT(VALUES(TableName[File Ref])),CALCULATE(SUM(TableName[Weight])))

but this is not work, do you have any idea or any thought?

Thank you.

 

File Ref is TEXT format

Weight is Number format

File RefWeight
27504845653752.5
275048456974.5
275048456974.5
2751197873752
27512558242310
275125602628.5
275125602628.5
2751261366880.5
2751290490351.5
27512942831240
27512942841537.5
2751294285332
2751306434888.5
2751306434888.5
  • Hi, Ericwhv , you might want to try this measure

    SUMX( DISTINCT( Table1[File Ref] ), CALCULATE( MAX( Table1[Weight] ) ) )

     

4 Replies

  • CNENFRNL's avatar
    CNENFRNL
    Community Champion

    Hi, Ericwhv , you might want to try this measure

    SUMX( DISTINCT( Table1[File Ref] ), CALCULATE( MAX( Table1[Weight] ) ) )

     

    • ed185's avatar
      ed185
      Regular Visitor

      Hi,

      Does anyone know what is the difference between :

      SUMX( DISTINCT( Table1[File Ref] ), CALCULATE( MAX( Table1[Weight] ) ) )

      and

      SUMX( DISTINCT( Table1[File Ref] ), MAX( Table1[Weight] ) )

       

      Both don't lead to the same results in my example.

      Thanks.

       

  • CNENFRNL 
    Thank you for your help it is work now! 🙂

    if you have time, could you mind to tell me why we use "MAX" instead of "SUM" here?

    thank you so much!

    • CNENFRNL's avatar
      CNENFRNL
      Community Champion

      Ericwhv , glad that my solution is of help. Further to your question, if SUM() is used, all weights of the same a unique File Ref will be summed up. You might want to try these 2 measures to see the differences.

      Test MAX = SUMX( DISTINCT( Table1[File Ref] ), CALCULATE( MAX( Table1[Weight] ) ) )
      
      Test SUM = SUMX( DISTINCT( Table1[File Ref] ), CALCULATE( SUM( Table1[Weight] ) ) )