skip to Main Content

power pivot to power bi

A Power BI Technique Mined from the Power Pivot Archives

Below, you will find one of our all-time favorite Power BI techniques. In the ten (yes ten) years we’ve been operating this site, we’ve written over 1,000 articles on Power BI.  Hard to imagine - even for us - but true.

Years ago, we first wrote up this technique in the context of Power Pivot – Power BI’s cousin and predecessor, which we like to call “Power BI in Excel.” 

Since the two products share the same brains (DAX and M), this technique is more relevant today than ever. Everything below is 100% legit for Power BI – the same data model “shape,” the same DAX, etc. – but now you can use it to power up your Power BI visuals, and not just PivotTables.  Enjoy! Smile


Nice Pivot, But I Only Want to See Months Where Eight
or More of My Stores Went Negative!

***Update:  Technique Extended, Workbook available

In a followup post I have added a slicer that lets the report user control the minimum number of stores required, rather than fixing it at 8 like this post does.  Also, the workbook is now available for download.

Find both in the followup post, located here.

Tales from Remote Consulting

Awhile back I left my job to start a new company.  I’m not yet ready to announce what that new company is about – I’m working hard on that and you folks will be the first to know.  Spoiler:  it’s about PowerPivot and Excel.

But in addition to hard work, there’s also a lot of waiting involved in all of that.  I’ve been filling the gaps with training and remote consulting to keep my head in the PowerPivot game.

Remote consulting in particular is a lot of fun – people send me a workbook, I spend 1-3 hours and build what they want, then send it back.  Gives me a good sampling of the problems that are “out there.”

One of those remote consulting jobs featured the problem pictured above (except that they had real data, and what I’m showing is 100% fake).

How Many Stores Fell Below Zero Each Month?

“In the pivot above, I only want to show Months where at least eight stores were negative.”

That’s one of the problems I solved for a reader whose initials are PR Smile

So how do we count how many stores went negative?

COUNTX Says “I’m a Strange Function, Only Use Me With Blanks!”

The first time I figured out SUMX (aka the 5-point palm exploding function technique), I remember looking at COUNTX and thinking “how the HECK is THAT function ever going to be useful?”

I mean, SUMX basically says “go evaluate an expression a bunch of times and sum up the result.”  So COUNTX means “go evaluate an expression a bunch of times and then count how many times you did it???”

I mean, aren’t these two formulas going to return the EXACT SAME RESULT?

  COUNTX(VALUES(Stores[StoreName]), any measure you choose)


Remember, the X functions are “loops” – they run through every “row” in that first argument – VALUES(Stores[StoreName]) in this case – and evaluate the second argument, which is typically a measure expression.

So if you have 15 total stores, COUNTX is going to evaluate your measure expression 15 times.  Won’t COUNTX always return 15 then?

Yeah, except when your measure sometimes returns BLANK().  Blanks will NOT be counted.  And we can do sinister, amazing things with that.  Get your evil scientist laugh ready.

Putting COUNTX to Work

Let’s write a new measure:

[Negative Growth Stores]=

This says “loop through Stores and count the number of times [SameStoreSales] was negative.

Let’s try that out on a pivot:


It’s Working, But Now How Do I Use It?


OK, now we slap a values filter on Rows so that we only see months with 3 or more negative stores…





So Far So Good – Filtered to Just Months With 8 or More Negative Stores!

Remove that Measure From Pivot, Add [SameStoreSales] Back

But I don’t want to see the number of negative stores, I just want to filter by it.  I want to see the [SameStoreSales] value for each store!

No problem:


[SameStoreSales] and [Store Name] Back on the Pivot,
[Negative Growth Stores] Removed but Still Filtered!

Neat huh?

I’ll extend this technique with some additional tricks next week.

Rob Collie

Rob Collie

One of the original engineering leaders behind Power BI and Power Pivot during his 14-year career at Microsoft, Rob Collie founded a consulting company in 2013 that is 100% devoted to “the new way forward” made possible by Power BI and its related technologies. Since 2013, PowerPivotPro has rapidly grown to become the leading firm in the industry, pioneering an agile, results-first methodology never before seen in the Business Intelligence space. A sought-after public speaker and author of the #1-selling Power BI book, Rob and his team would like to help you revolutionize your business and your career.

This Post Has 8 Comments
  1. Looks nice, but I’m hoping the snapshot you’re showing isn’t the whole picture (width-wise) as the months shown on the bottom picture have fewer than 8 stores in the negative for some months. Also that formula and the picture are misleading (in my interpretation). Your description was to show (loop) the number of times same store was negative. I’m seeing 0% and positive values. So why is it showing everything? I ain’t no expert (yes that’s fancy speak) but that just don’t look right for what I think you should see. BUT.. I have been known to be wrong before. Just don’t tell my wife.

    1. Yeah the report is 33 columns wide – there are 33 stores total. So yes, many negative stores are missing from the screenshots. I really need to switch this blog to a widescreen format 🙂

      The *measure* loops through the stores and counts them up. But the *filter* removes *months* that don’t have 8 stores negative. All stores are displayed no matter what. Does that clarify?

  2. I am unable to use this workbook in my Excel 2013 as it says something about needing to upgrade. My presumption is that the workbook starts with the raw data and I can follow through with your post to achieve your results?


Leave a Reply

Your email address will not be published. Required fields are marked *