Forum Discussion
Summing column once per distinct value in table
I feel this should be easy, but I have not been able to write a measure that accomplishes it how I need it to.
To explain, here is an example table of how my data looks:
| Job | Order Date | Create Date | Amount |
| 1 | 1/1/2024 | 2/2023 | 54,500 |
| 2 | 1/1/2024 | 2/2023 | 68,400 |
| 1 | 1/1/2024 | 2/2023 | 54,500 |
| 2 | 1/1/2024 | 2/2023 | 68,400 |
I need to write a measure that would take the above table and sum the amount column only for each distinct job. In this example this would be 54,500 + 68400. The other part of the specifications here is this must be wrapped in a calculation function so I can use:
Try this measure:
Sum Distinct Amount = VAR vTable = SUMMARIZE ( Test, Test[Job], Test[Amount] ) VAR vResult = CALCULATE ( SUMX ( vTable, Test[Amount] ), USERELATIONSHIP ( Test[CreateDate], 'Date Table'[Date] ) ) RETURN vResult
2 Replies
- DataInsights
Super User
Try this measure:
Sum Distinct Amount = VAR vTable = SUMMARIZE ( Test, Test[Job], Test[Amount] ) VAR vResult = CALCULATE ( SUMX ( vTable, Test[Amount] ), USERELATIONSHIP ( Test[CreateDate], 'Date Table'[Date] ) ) RETURN vResult- AppleMan
Helper III
Hi thank you, that seems to be working somewhat. I am having an issue where the date slicers (which are hooked up to a different column than the create date) are not properly filtering these values as they should and are filtering them based on the wrong date field. I have used UseRelationship many times so not sure why it is not functioning as intended. But I can see in the table when testing that it is only including one line for the amount per job so I will mark your answer as the solution. I just need to troubleshoot this date issue next.