'Is there a possibility in DAX to do a distinct over several columns?
I'd like to summarize the following ID's with it's prices on a distinct bases. So that means for the ID 123 both prices get summarize cause they are different. But for the ID 789 the price should only count once. So as result I would like to have 8'500 instead of 11'500. I've to solve this problem in DAX.
ID | Price |
---|---|
123 | 1500 |
456 | 2000 |
789 | 3000 |
123 | 2000 |
789 | 3000 |
I tried something like: CALCULATE(SUM(Tablename[Price]), FILTER(Tablename, DISTINCT(Tablename[ID])), FILTER(Tablename, DISTINCT(Tablename[Price])))
OR
SUMX(DISTINCT(Tablename[ID]), FIRSTNONBLANK(Tablename[Price], 0))
but neither of this works out.
Thx in advandce for your help. Yannick
Solution 1:[1]
my solution at the end was the following measure:
MEASURE Vehicle_dim[dis_sum] =
VAR vTable =
SUMMARIZE (
Vehicle,
Vehicle[vehicleId],
Vehicle[Price]
)
VAR vSum =
SUMX(
vTable,
Vehicle[Price]
)
VAR vCnt =
COUNTROWS (
DISTINCT (
SELECTCOLUMNS (
Vehicle,
"vehicleId", Vehicle[vehicleId],
"Price", Vehicle[Price]
)
)
)
VAR Result =
DIVIDE ( vSum, vCnt )
RETURN
Result
Solution 2:[2]
It's hard to understand what you are going after out of context. Summing prices doesn't make much sense to me out of context of what you are doing.
This is easy if you can create a calculated table first:
=DISTINCT('Table')
Then do your SUM against the calculated table.
It's also easy to create the table in Power Query with Table.Distinct
.
It's difficult to access the column of this calculated table in DAX without creating it first.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Yannick |
Solution 2 | TheRizza |