By Dany Hoter

*Intro by Avi: I have often been asked, about ways to provide an “input” to the Power Pivot model from Excel. **Disconnected Slicers** are a popular way to do this. But with Excel and Power Pivot, there is always more than one way to accomplish a task. Dany shows us how, while making histograms easier to use. He uses a filter dropdown, which even works with Excel Online – inside a browser! Here is the end result, read on to learn how and download file.*

*Take it away Dany…*

### Introduction

Creating a histogram in Excel based on Power Pivot is not as easy as it should be.

The method I use is no different from what others have already blogged and wrote about. There is even a **solution** that calculates the number of bins in a histogram with a formula that is based on the total number of cases.

My take on the problem was to let the user choose in run time what is the interval between each bin as a percentage and to show the number of bins accordingly.

### Business Case

The model contains data about a service that is in its infancy and so the users experience a relatively high number of errors.

The managers responsible for the service posed the following request:

“We want to see a histogram of the sessions showing how many users have experienced no errors in all the sessions they initiated, how many experienced errors in 10% of the sessions, 20% of the sessions … all the way to these poor users who saw nothing but errors in 100% of the sessions (Told you it is in early stage…)

### Solution

We had a table with the Users, a table with Sessions and a table with Errors for Sessions.

The actual histogram was created by adding the disconnected table ‘Buckets’ for the bins and creating the following measures:

– Total sessions from the sessions’ table

Sessions:=DISTINCTCOUNT(Sessions1[SessionId])

– Sessions in error from the errors table

FailedSession:=DISTINCTCOUNT(Errors[SessionId])

– Fail ratio as a ratio between the previous two

Failure:=DIVIDE([FailedSession],[Sessions])

– Users for a histogram bin as below

Bucket := CALCULATE (

COUNTROWS (

FILTER (

Users,

AND (

[FailRatio] >= MIN ( Buckets[From] ),

[FailRatio] < MAX ( Buckets[To] )

)

)

))

As this was pretty easy I wanted to add the option of the user to define the # of buckets at run time The problem is that the bins from and to columns are calculated columns that need to be refreshed in order to produce new values. So the user need to input the new interval between buckets and then trigger a refresh that will take the new value and use it to calculate the columns in the buckets table.

The buckets table is a linked table with columns that looks like this:

It has 30 rows to allow for a large number of bins. The value of the Interval is used to calculate the bins’ ranges.

A single cell pivot based on the buckets table is used to trigger a refresh just for the buckets table.

The first state show 10% as the interval and 10% as the value from the buckets table (average(interval) )

The user changes the value to 20% which recalculated the Excel buckets table.

After that, user refreshes the tiny pivot that says Refresh here by right clicking and choosing refresh.

At this point the buckets table is refreshed in the model and the users are spread between the new bins.

Voila – bins are now shown in 20% intervals! The last column shows sessions at 100% error. All the remaining columns in Buckets table with the from value above 100% are hidden by the pivot chart because no data is returned for those.

In order to enable the input from Excel web, I have used pivot filter as the input method. For Desktop use you could simply allow user to type in or select a value from dropdown, you could even auto-refresh once the input value is changed.