Reputation: 15
I would like to calculate column 'E' in DAX
I wanted to count distinct 'B' based on 'C' and filter on 'D' = instock.
I later want to sum column E -- what is the best way to do this to exclude the duplications
Thanks in advance
Upvotes: 0
Views: 92
Reputation: 2615
Your question is split into 2 parts: Go step by step then:
First Step Code:
Result =
CALCULATE (
DISTINCTCOUNT ( 'Product'[size] ),
ALLEXCEPT ( 'Product', 'Product'[product code] ),
'Product'[stock] = "instock"
)
Second Step:
Result =
VAR TblSummary =
ADDCOLUMNS (
VALUES ( 'Product'[product code] ),
"DISCTotal",
CALCULATE (
DISTINCTCOUNT ( 'Product'[size] ),
ALLEXCEPT ( 'Product', 'Product'[product code] ),
'Product'[stock] = "instock"
)
)
RETURN
SUMX ( TblSummary, [DISCTotal] )
Upvotes: 0
Reputation: 9062
You mean you want a Calculated Column?
=
VAR ThisProductCode = 'Table'[product code]
RETURN
CALCULATE(
DISTINCTCOUNT( 'Table'[size] ),
FILTER(
'Table',
'Table'[product code] = ThisProductCode
&& 'Table'[stock] = "instock"
)
)
Not sure what you mean by your second request, though.
Upvotes: 1