Forum Discussion
filtering not by the filter itself
Hi,
I have a sample data here:
Product Year Color Sales Class
| Pen | 2010 | Red | 764 | Stationary |
| Pencil | 2010 | Green | 977 | Stationary |
| Paper | 2010 | Red | 249 | Stationary |
| Ruler | 2010 | Blue | 971 | Stationary |
| Sticker | 2010 | Red | 462 | Stationary |
| Envelope | 2010 | Green | 636 | Stationary |
| Cardboard | 2010 | Red | 700 | Stationary |
| Binder | 2010 | Blue | 580 | Stationary |
| Memo | 2010 | Blue | 332 | Stationary |
| Notebook | 2010 | Red | 613 | Stationary |
| Refillpad | 2010 | Green | 123 | Stationary |
| Pen | 2011 | Green | 874 | Stationary |
| Pencil | 2011 | Blue | 270 | Stationary |
| Paper | 2011 | Red | 643 | Stationary |
| Ruler | 2011 | Red | 456 | Stationary |
| Sticker | 2011 | Red | 292 | Stationary |
| Envelope | 2011 | Blue | 551 | Stationary |
| Cardboard | 2011 | Green | 117 | Stationary |
| Binder | 2011 | Red | 86 | Stationary |
| Memo | 2011 | Red | 416 | Stationary |
| Notebook | 2011 | Green | 709 | Stationary |
| Refillpad | 2011 | Green | 874 | Stationary |
| Pen | 2012 | Red | 487 | Stationary |
| Pencil | 2012 | Red | 398 | Stationary |
| Paper | 2012 | Red | 445 | Stationary |
| Ruler | 2012 | Blue | 115 | Stationary |
| Sticker | 2012 | Red | 488 | Stationary |
| Envelope | 2012 | Blue | 330 | Stationary |
| Cardboard | 2012 | Blue | 900 | Stationary |
| Binder | 2012 | Blue | 567 | Stationary |
| Memo | 2012 | Green | 524 | Stationary |
| Notebook | 2012 | Red | 877 | Stationary |
| Refillpad | 2012 | Blue | 215 | Stationary |
| Fridge | 2010 | Blue | 315 | Appliance |
| Washing Machine | 2010 | Green | 151 | Appliance |
| Stove | 2010 | Red | 254 | Appliance |
| Dishwasher | 2010 | Blue | 846 | Appliance |
| Boiler | 2010 | Blue | 354 | Appliance |
| Toaster | 2010 | Red | 48 | Appliance |
| Fridge | 2011 | Blue | 312 | Appliance |
| Washing Machine | 2011 | Red | 41 | Appliance |
| Stove | 2011 | Red | 123 | Appliance |
| Dishwasher | 2011 | Green | 478 | Appliance |
| Boiler | 2011 | Red | 54 | Appliance |
| Toaster | 2011 | Red | 65 | Appliance |
| Fridge | 2012 | Blue | 98 | Appliance |
| Washing Machine | 2012 | Blue | 348 | Appliance |
| Stove | 2012 | Blue | 786 | Appliance |
| Dishwasher | 2012 | Green | 843 | Appliance |
| Boiler | 2012 | Green | 25 | Appliance |
| Toaster | 2012 | Red | 489 | Appliance |
Is it possible to create a measure, such that when I filter on the product, it returns the sales of all the product with the same color in 2010, but not the sales of that product itself? i.e. if I have a slicer of product, when I click on "Memo", the measure will give me sales of all the blue product in 2010, which is 3398.
Thanks for any help.
JC
Hi Anonymous,
Try this for your measure:
Measure = VAR _Color = CALCULATE ( SELECTEDVALUE( Table1[Color] ); Table1[Year] = 2010 ) RETURN CALCULATE ( SUM ( Table1[Sales] ); ALL ( Table1[Product] ); Table1[Color] = _Color; Table1[Year] = 2010 )See it at work in the attached file. I've also included another measure that calculates the sales excluding the product you select in the slicer:
Measure2 = VAR _Color = CALCULATE ( SELECTEDVALUE( Table1[Color] ); Table1[Year] = 2010 ) RETURN CALCULATE ( SUM ( Table1[Sales] ); ALL ( Table1[Product] ); Table1[Color] = _Color; Table1[Year] = 2010; FILTER ( ALL ( Table1[Product] ); Table1[Product] <> SELECTEDVALUE ( Table1[Product] ) ) )Although it would probably be better to have the the year (2010 in this case) selected in a slicer than hard-coded in the measure
2 Replies
- AlB
Community Champion
Hi Anonymous,
Try this for your measure:
Measure = VAR _Color = CALCULATE ( SELECTEDVALUE( Table1[Color] ); Table1[Year] = 2010 ) RETURN CALCULATE ( SUM ( Table1[Sales] ); ALL ( Table1[Product] ); Table1[Color] = _Color; Table1[Year] = 2010 )See it at work in the attached file. I've also included another measure that calculates the sales excluding the product you select in the slicer:
Measure2 = VAR _Color = CALCULATE ( SELECTEDVALUE( Table1[Color] ); Table1[Year] = 2010 ) RETURN CALCULATE ( SUM ( Table1[Sales] ); ALL ( Table1[Product] ); Table1[Color] = _Color; Table1[Year] = 2010; FILTER ( ALL ( Table1[Product] ); Table1[Product] <> SELECTEDVALUE ( Table1[Product] ) ) )Although it would probably be better to have the the year (2010 in this case) selected in a slicer than hard-coded in the measure - v-lili6-msft
Community Support
hi, Anonymous
For year 2010, Is it a fixed value or a variable value.
If is a slicer, you could try this measure as below:
Measure = var color=CALCULATETABLE(VALUES(Table1[Color]),ALLSELECTED(Table1[Product])) return CALCULATE(SUM(Table1[Sales]),FILTER(ALLEXCEPT(Table1,Table1[Year]),Table1[Color] in color))
Result:
and here is demo pbix, please try it.
Best Regards,
Lin