Becoming one with CALCULATE()

Guest Post by Scott Senkeresty

Intro from Rob

Hey, it starts out simple and powerful:  CALCULATE is the SUMIF you always wished you’d had.  It works in pivots.  It’s the “anything IF.”  It’s amazing, really, how many doors it opens.

Of course, CALCULATE is designed to be powerful in ways we can’t even IMAGINE in our first day/week/month of using it.  You can spend years discovering all the things it can do – and that’s a good thing!  But sooner or later you’re going to hit something with CALCULATE that makes you scratch your head – why is it returning THOSE results?

I myself entered this twilight zone with the Precedence Project – a series of posts that I quickly abandoned.  It turns out that, practically speaking, you don’t need to achieve deep theoretical understanding of this stuff in order to achieve great results.

Below, however, Scott does a great job of resolving those mysteries.  And he does so by “channeling” two old friends who live at the base of the Alps.  Take it away, Scott…

Going to “Graduate School”


All right, so I’ve read Rob’s book a few times.  (Heck, I am credited as tech editor on it.)  I’ve devoured PowerPivotPro University.  So now what, I ask Rob?

“Go forth and conquer – data is your ocean,” is his answer.  He’s a practical sort of guy.  Me, though?  I’m never satisfied until I’ve completely torn the machine apart.

So, as I hinted in my last post, I went to graduate school and spent a few intense days engrossed in Marco and Alberto’s book.


Read the Rest

The GFITW “Loses” an ALL()


Yes, We’ve Seen This Image Before and I Am Sure We Will See it Again

Jump in the Wayback Machine…

In the Spring of 2011, I dove into a Power Pivot project that I thought was going to be simple, but even today remains the most complex thing I’ve ever done in DAX.  I think it’s fair to say that the experience, at the time, was traumatizing.  (The client’s business logic itself was/is incredibly complicated.  It’s 100% legitimate, but I think barometric pressure might be factored into their budget/actuals ratios.  Kidding.)

But like many difficult experiences, a lot of good came of it as well:

  1. I learned a ton – it forced me to advance my Power Pivot knowledge significantly
  2. It demonstrated to me that Power Pivot essentially had no “ceiling” – it could handle almost anything
  3. It became a Microsoft case study
  4. It “spawned” the GFITW.

Ah yes, the Greatest Formula in the World.  The solution to all our custom calendar needs, and a pattern I’ve repeated hundreds of times since.  On the blog, in the book, in client workbooks, everywhere.

Well it turns out, the GFITW could afford to go on a diet.

Um, Yeah.  The First ALL Isn’t Necessary (But Doesn’t Cause Problems)

Here’s the “classic” GFITW pattern:

Read the Rest

The Greatest Formula in the World, Part One

  “Play Write the greatest song formula in the world, or I’ll eat your souls.”-From “Tribute,” by Tenacious DAX A Do-It-Yourself Time Machine You remember the Great Precedence Project?  Well, I have shelved it for now, for two reasons: Creating an exhaustive list of all the precedence rules in PowerPivot formulas was going to be…  exhausting. I didn’t really need to boil the philosophical ocean in search of deep underlying meaning, because on further inspection, I already had the Greatest…

Read the Rest

Running Totals Without a Traditional Calendar Table

PowerPivot provides a host of great functions like DATESYTD, DATESMTD, DATESBETWEEN, etc. that are useful for calculating many things, including a running total. But with the exception of DATESBETWEEN, I seldom get to use any of those “time intelligence” functions, for the simple reason that our clients almost never operate on a traditional calendar. I very often find myself working with a “calendar” that looks like this: Can’t Use Time Intelligence Functions With a Calendar Like This And sometimes I…

Read the Rest

Precedence Part 3: ALLEXCEPT vs. ALL w/ VALUES

  “However…  you do have ALL() the characteristics of a dog, Gary.  ALLEXCEPT() loyalty…”       This will be a quick one.  I think. In part two, we left off with the observation that VALUES() can “trump” ALL() even when VALUES() is applied to a column that is not on the pivot: [ALL then VALUES of field not on pivot] = [Total Sales](ALL(Periods),VALUES(Periods[Period Num])) One thing I have often puzzled over is this:  how does a combination of ALL(Table),…

Read the Rest

Precedence Project Part Two: VALUES()

OK, picking up from part one… Let’s start with a simplified version of last post’s pivot – remove one of the row fields, and all of the measures but the base Total Sales measure: Now let’s add a measure that sets Year to ALL: [ALL Year Sales] = [Total Sales](ALL(Periods[Year])) Note that all of the orange cells have the same value – they are all Q1 cells and differ only on Year, so the all Year measure means each orange…

Read the Rest

The Great Precedence Project (Filter Rules for DAX)

“Wait a minute. There might be legal precedent. Of course. Land snatching. Let's see, land, la-land...see snatch. snatch...snatch...ah! Haley vs. United states. Haley 7, United States nothing. You see, it can be done!”     Keeping filters straight as they pile up Some example questions to ponder: Within a FILTER or a CALCULATE, does the order of the filter arguments ever make a difference? Does using an ALL inside of a FILTER yield different results than using an ALL inside…

Read the Rest