Forum Discussion
Help getting the right total in matrix table
- 4 years ago
rmsl , I think first two should be simple
# Client that bought selected product [Expected Result = 1]
Count(Table[Client])
Amount spent in selected product [Expected Result = £30]
Sum(Table[Amount])
Total amount spent by client who bought selected product [Expected Result = £60]
Measure =
var _tab = summarize(allselected(Table), Table[Client])
return
Calculate(sum(Table), Filter(all(Table), Table[Client] in _tab) )
- Anonymous4 years ago
Hi rmsl ,
You can create two slicers.
A slicer for normal selection of Products.
Another slicer to exclude the selected Product.
Here are the steps you can follow:
1. Create calculated table.
optional = DISTINCT('Table'[Product])not optional = DISTINCT('optional'[Product])2. Create measure.
Client that bought selected product = var _select= SELECTEDVALUE('optional'[Product]) return CALCULATE(COUNT('Table'[Amount]),FILTER(ALL('Table'),'Table'[Product]=_select))Amount spent in selected product = var _select=SELECTEDVALUE('optional'[Product]) return CALCULATE( SUM('Table'[Amount]), FILTER(ALL('Table'), 'Table'[Product]=_select))Total amount spent by client who bought selected product = var _select=SELECTEDVALUE('optional'[Product]) var _noselect=SELECTEDVALUE('not optional'[Product]) var _selectcolumn= SELECTCOLUMNS(FILTER(ALL('Table'),'Table'[Product]=_select),"clinet",[Client ID]) return IF( HASONEVALUE('not optional'[Product]), CALCULATE(SUM('Table'[Amount]),FILTER(ALL('Table'),'Table'[Client ID] in _selectcolumn&&'Table'[Product]<>_noselect)), CALCULATE(SUM('Table'[Amount]),FILTER(ALL('Table'),'Table'[Client ID] in _selectcolumn)) )3. Result:
Treat [Product] of optional table as slicer 1
Treat [Product] of not optional table as slicer 2.
When slicer 2 is not selected, it is calculated normally and displays 180.
When slicer 2 selects a value, such as Product4, it will not contain the value of Product4, and it will be displayed as 150
If you need pbix, please click here.
Best Regards,
Liu Yang
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly
At the end I have used amitchandak solution as it did not create additional tables.
Regarding the product excluded, I have simply created another Amount Column with £0 for Product 4 as follow;
I prefered this solution as Anonymous solution who created 2 tables but if you do not mind about the two additional tables, then Anonymous solution would work too.
Thanks again both for your help on this issue.
Best,
R
Client ID | Product | Amount | Amount (excl P4)
Client 1 | Product 1 | £10 | £10
Client 1 | Product 2 | £30 | £30
Client 1 | Product 3 | £20 | £20
Client 2 | Product 1 | £25 | £25
Client 2 | Product 3 | £35 | £35
Client 3 | Product 1 | £30 | £30
Client 3 | Product 4 | £30 | £0