Forum Discussion
Raymo3u99
7 years agoHelper I
Comparing values from 2 different selections
I have a table with the following columns: Product, Date, Cost I want to be able to have two slicers showing product. User can select a product from each slicer and I need to compare the cost...
- 7 years ago
So the first part of your requirement you could just do with a single slicer on Product that is set to allow multiple selections.
Calculating the variance of a multi-select is a bit more involved, but not impossible (see the table on the right above). I did this with the following code:
Variance = var _selectedProducts = ALLSELECTED(Table1[Product]) var _countSelected = COUNTROWS(_selectedProducts) var _prod1 = MINX(_selectedProducts,[Product]) var _prod2 = MAXX(_selectedProducts,[Product]) var _prod1Cost = CALCULATE(sum(Table1[Cost]), Table1[Product] = _prod1) var _prod2Cost = CALCULATE(sum(Table1[Cost]), Table1[Product] = _prod2) var _result = IF(_countSelected = 2 && SELECTEDVALUE(Table1[Product]) = _prod1, _prod2Cost - _prod1Cost) RETURN _result
d_gosbell
7 years agoSuper User
So the first part of your requirement you could just do with a single slicer on Product that is set to allow multiple selections.
Calculating the variance of a multi-select is a bit more involved, but not impossible (see the table on the right above). I did this with the following code:
Variance = var _selectedProducts = ALLSELECTED(Table1[Product]) var _countSelected = COUNTROWS(_selectedProducts) var _prod1 = MINX(_selectedProducts,[Product]) var _prod2 = MAXX(_selectedProducts,[Product]) var _prod1Cost = CALCULATE(sum(Table1[Cost]), Table1[Product] = _prod1) var _prod2Cost = CALCULATE(sum(Table1[Cost]), Table1[Product] = _prod2) var _result = IF(_countSelected = 2 && SELECTEDVALUE(Table1[Product]) = _prod1, _prod2Cost - _prod1Cost) RETURN _result