Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
7 years ago

Sum based on unique ID

Hi Guys,

 

I have a problem which shouldnt be that difficult to solve, but I'm new to DAX and can't handle it.

 

What I am searching for is the Sum of values based on a ID. 
Example:

ID | VALUE

1      1 

1      2 

2      3

2      3

3      4

3      1 

3      3

 

Result should be

ID 

1 =3

2 = 6

3 = 8

11 Replies

  • If you put it in a table in PowerBI you get your results right? Why do you need it in an aggregated format? It will do it at "run time"

     

     

    • Anonymous's avatar
      Anonymous
      Not applicable

      I would like to have it as a measure instead as a additional column in the table.. The GroupBy Function also doesnt work, it doesnt add the values though I selected it.. 

    • richardverburg's avatar
      richardverburg
      Helper I

      Otherwise you can Add a table in PowerBI with the following DAX:

      Table = SUMMARIZE(Sheet1; Sheet1[ID]; "Total Value"; sum(Sheet1[VALUE])) 

      This code will return an aggregated table. 

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

    Hi Anonymous,

     

    One sample for your reference. Here I create a calculated table using the formula.

     

    Table = SUMMARIZE(Table1,Table1[ID],"ID ",Table1[ID]&"="&SUM(Table1[VALUE]))

    The result as below:

     

     

    If it doesn't meet your requirement, please refer to Table2.

     

    Table2 = SUMMARIZE(Table1,Table1[ID],"ID ",SUM(Table1[VALUE]))

    For more details, please check the pbix as attached.

     

    Regards,

    Frank

    • Anonymous's avatar
      Anonymous
      Not applicable

      Thanks for your answer. Im getting the following Error:

      "The expression refers to multiple columns. Multiple Columns cannot be converted to a scalar value"

       

       

  • Hi,

     

    Drag ID to the Table visual and write this measure

     

    =SUM(Data[Value])

     

    Hope this helps.

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

    Hi Anonymous,

     

    Does that make sense? If so, kindly mark my answer as a solution to close the case.

     

    Regards,
    Frank

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

    Hi Anonymous,

     

    What is your excepted result then?

     

    Regards,

    Frank