# Need PowerPivot Slicer based on Measure calculations



## powerpivotlegal (May 23, 2014)

Hello,

Is it possible to create a slicer with the options "Over Budget", "Under Budget" based on values calculated from a measure?

In the sample pivot table results below, "Remaining Budget" and "%Budget Used" are the measures. I want a slicer that returns all the Matter Numbers (e.g. "6828400-001002) by quarter that are Over/Under Budget.

I wanted something more user-friendly than just a KPI.

Row LabelsFees BilledUnbilled FeesBudgetsRemaining Budget%Budget Used68284000-001002$339,351.56$22,731.27$400,000.00 $   37,917.1790.52%FY14-Q1$59,168.92$0.00$100,000.00 $   40,831.0859.17%FY14-Q2$124,424.75$0.00$100,000.00 $  (24,424.75)124.42%FY14-Q3$155,757.89$22,731.27$100,000.00 $  (78,489.16)178.49%FY14-Q4  $100,000.00 $ 100,000.00 68284000-001003$77,441.77$922.50$100,000.00 $   21,635.7378.36%FY14-Q1$41,811.00$0.00$25,000.00 $  (16,811.00)167.24%FY14-Q2$16,479.73$0.00$25,000.00 $     8,520.2765.92%FY14-Q3$19,151.04$922.50$25,000.00 $     4,926.4680.29%FY14-Q4  $25,000.00 $   25,000.00 68284000-001004$79,337.47$19,665.11$100,000.00 $       997.4299.00%FY14-Q1$23,081.37$0.00$25,000.00 $     1,918.6392.33%FY14-Q2$50,663.50$0.00$25,000.00 $  (25,663.50)202.65%FY14-Q3$5,592.60$19,665.11$25,000.00 $      (257.71)101.03%FY14-Q4  $25,000.00 $   25,000.00 

<tbody>

</tbody><colgroup><col><col><col><col><col><col></colgroup>

Any help would be greatly appreciated.


----------



## scottsen (May 24, 2014)

This is doable, if a bit of a pain to explain.  You will need to use a disconnected slicer (to use a powerpivotpro term).  Google his site for some of the techniques there.

I think what I would do is have another measure that returns "1" only if a row is over budget AND the disconnected slicer is set to Over Budget.  Then use "normal" excel techniques to filter a column with the 0/1 to only shows "1"s.   You could then hide that column.

Make sense?


----------



## powerpivotlegal (May 27, 2014)

Hi Scott,

Not sure I understand the second approach.  

I created the measure  OverBudget:=IF([%Budget Used]>=1,1,0) to give me the 0 and 1 values in a "Over Budget" column.  I then created a table in PowerPivot with these options to create the disconnected slicer.  

Not sure what you mean by filtering the column.  The pivot table will not allow me to filter on the new "Over Budget" column. Plus, how do I link the disconnected slicer?  The powerpivotpro posts talk about writing additional measures.


----------



## scottsen (May 27, 2014)

Say the table supporting your disconnected "Over Budget" slicer looks like

Name               Value
Over Budget      1
Under Budget     2

Let's call it OverUnderIndicator

So, you write a measure say...    

ShouldInclude := COUNTROWS(OverUnderIndicator) = 2 ||
                         ( MIN(OverUnderIndicator[Value]) = 1 && [%Budget Used] >= 1 ) ||
                         ( MIN(OverUnderIndicator[Value]) = 2 && [%Budget Used] < 1 )

So, assuming you put OverUnderIndicator[Name] on a slicer, and Matter Numbers on Rows... you could add this measure on values.
It is going to return TRUE if 
 - you haven't sliced (COUNTROWS = 2), or
 - if you sliced to OverBudget (min = 1) and you are over budget (% >= 1), or
 - if you sliced to UnderBudget (min = 2) and you are under budget (% < 1)

So, at this point you have a measure flipping around between true and false, but no ACTUAL filtering happening.  This is where I am saying "use normal excel filtering".

Just use a "Value Filter" (from the drop down menu on top left of Pivot), to only include rows where above measure is true.


----------



## powerpivotlegal (May 28, 2014)

I now have a slicer captioned "Name" with Over Budget and Under Budget for slicer options.  The measure populates the "ShouldInclude" column of the PivotTable with all TRUES when no slicer option is selected.  If I select "Over Budget", the matters over budget show FALSE.  I think this is all good so far.  

MattersFees BilledUnbilled FeesSum of Quarterly Budget%Budget UsedShouldInclude68284000-001002$339,351.56$22,731.27$400,000.0090.52%FALSE68284000-001003$77,441.77$922.50$100,000.0078.36%FALSE68284000-001004$79,337.47$19,665.11$100,000.0099.00%FALSE68284000-001005$176,294.47$325.50$100,000.00176.62%TRUE68284000-001006$20,238.43$2,254.50$100,000.0022.49%FALSE68284000-001007$103,016.44$8,528.33$100,000.00111.54%TRUE68284000-001008$47,577.43$10,251.56$100,000.0057.83%FALSE68284000-001009$78,737.76$637.00$100,000.0079.37%FALSE68284000-001010$62,752.89$192,582.73$100,000.00255.34%TRUE68284000-001011$63,112.18$10,694.01$100,000.0073.81%FALSE68284000-001012$46,588.91$6,535.50$100,000.0053.12%FALSE

<tbody>

</tbody><colgroup><col><col><col><col><col><col></colgroup>

However, the Value Filter does not work when I try to enter:

Show Items for which "ShouldInclude" equals TRUE.  The error message wants me to enter a number in some range.  It does not matter if I set the format to text.  If I try to set the filter to eqauls "1" (the value of Over Budget), all data in the pivot table disappears.

What am I missing?


----------



## scottsen (May 28, 2014)

Ya know, I was just playing with something similiar, and ended up switching away from TRUE/FALSE, and going with 1/0, because the Value Filter was much happier with that.  Give that a try.


----------



## powerpivotlegal (May 28, 2014)

Not sure where I'm supposed to put 1/0.  In the measure?  If so, how?  In the table, OverUnderIndicator?  Sorry for all the questions, but I'm new to DAX formulas, especially COUNT or IF(Values) formulas.  My background is legal not finance/analytics.


----------



## scottsen (May 28, 2014)

No apology necessary.  Most of my clients are the same, and it's what I love about Power Pivot.  Power into EXACTLY the right hands 

We had:
ShouldInclude := COUNTROWS(OverUnderIndicator) = 2 ||
( MIN(OverUnderIndicator[Value]) = 1 && [%Budget Used] >= 1 ) ||
( MIN(OverUnderIndicator[Value]) = 2 && [%Budget Used] < 1 )

Let's change that to:
ShouldInclude := IF(COUNTROWS(OverUnderIndicator) = 2 ||
( MIN(OverUnderIndicator[Value]) = 1 && [%Budget Used] >= 1 ) ||
( MIN(OverUnderIndicator[Value]) = 2 && [%Budget Used] < 1 ), 1, 0)

So that instead of returning TRUE/FALSE, that measure will return 1 or 0.  That should also the Value Filter to work.


----------

