Skip to main content

The Power of CALCULATE in Power BI

Last week in my blog and video I discussed how Power BI could have made my life as a teacher much easier.  It is not that Power BI can do things that I could not on my own.  It is the fact that Power BI could have saved me so much time.  This led me to some thoughts and questions.  

  • How could I have impacted the students more in the classroom with this extra time? 
  • Would teachers who were not analyzing student data due to time constraints now start? 
  • How can I make the data tell my students a story that gives them an accurate picture of their progress?

 That last question is what leads to this week’s blog.  

Many times the metrics (which is just a fancy word for "numbers") of what we want to show are easy to do by hand with a basic math background.  Although easy, it can be very time consuming when dealing with different groups of data: like 6 periods of students instead of 1 period. When we want to do these calculations quickly with minimal effort in Power BI it is not as straightforward as a process as if just doing them by hand.  

For example, what if I want each one of my 130 students to see his or her grade compared to the first period's class average? Typically, I would have all the grades stored in a column so I cannot use a simple "measure".  A measure will look at one column and perform an operation over the entire column. For example, if the numbers 8, 9, 10, and 11 were stored in a column and we programmed our measure for the sum we would get 38.  But what if, I just wanted the sum of the first two numbers in the column.  This is where it is easy to do by hand, but a little harder to do with the coding in Power BI.  Let me explain further.

A basic measure in Power BI will always be filtered down in a report visual (table, matrix, chart, etc.) based on what is called a row-level context.  So, if in a table I only had one row that contained the formula for finding the average of all the grades stored in a column show up in a table I would see the average of all my students.  The minute I add student names to the table, I will now have more than just one row of data.  I will have one row for each student’s name. I will also see the unique average of each student next to their name because each row average is now filtered down based on the student name.  The previous number of the entire average for all students has now disappeared.  Usually, that’s exactly what we want.  What if I wanted my students to be able to see their average grade right next to the period average grade for that assignment?  What if I wanted my student to see their average grade compared to all of the students I teach who took the same assignment?  That’s where the function CALCULATE comes into the story.  


CALCULATE is a DAX function that allows you to take a basic measure calculation and modify the row-level context. Woah!  CALCULATE is super powerful  For my prior example, I can override the student filtering the average calculation and I can have the calculation filtered by something that isn’t in the row,  a select few items in the row, or ignore/use the outside slicer filters.  Confused yet?  If not you are probably a master of Power BI and DAX already.  If you are confused, then welcome to my world when I first started learning Power BI.  I have a very strong mathematics background, but when having to apply my understanding of mathematics to telling a computer how to do my calculation without just saying it in normal words took me a while to wrap my head around.

So, please follow along with me in this video as I attempt to help you understand how the function CALCULATE works along with the help of the other DAX functions ALL, ALLSELECTED, and ALLEXCEPT.  This demo will for sure shed light on education data to help a classroom teacher make their data come alive.  If you are not a classroom teacher this demo is just as useful as you can apply it to financial, medical, and sports data just to name a few.

 


Comments

  1. This comment has been removed by the author.

    ReplyDelete
  2. Great article with very unique content.
    Thank you for sharing it..

    Keep Updating...

    Power BI Training

    ReplyDelete
  3. Great article, I really like it. Using The MAXX DAX Function In Power BI To Calculate Recent Values In Your Data. To know more, visit Enterprise DNA.

    ReplyDelete
  4. Designing Power BI Reports Wow, cool post. I'd like to write like this too - taking time and real hard work to make a great article... but I put things off too much and never seem to get started. Thanks though.

    ReplyDelete
  5. Power themes This particular is usually apparently essential and moreover outstanding truth along with for sure fair-minded and moreover admittedly useful My business is looking to find in advance designed for this specific useful stuffs…

    ReplyDelete
  6. You completed a few fine points there. I did a search on the subject and found nearly all persons will go along with with your blog. Sales velocity calculation

    ReplyDelete

Post a Comment

Popular posts from this blog

Best Practice To Trim Before Removing Duplicates or Merging In Power Query Editor

In last week’s blog, I wrote and did a video about how to remove duplicate records and keep the most recent entry as long as a date column was part of the data source.   I came across the scenario while giving training on Power BI with my company Pragmatic Works.   See the video below:     This week, while doing another two-day training I came across a different scenario from a follow-up conversation from day 1.   I had explained how to remove duplicate records and one of the students started working on a Power BI project she has for her company.   On day 2 the student informed me that her remove duplicates step was not working.   I said that is odd and I asked to see the data.   In one of her table visuals, I could see that it appeared that a few of the records had duplicates based on the name column.   After further investigation though, we figured out the culprit.     She had done all the steps correctly, but it was a data integrity issue.   In her data source, the perso

Relating "Related Tables" to Baseball because I Miss Sports

I miss sports. In particular, I miss baseball. Between learning more Power BI functions and the ins-and-outs of DAX, I've turned to Netflix to fill the deep caverns left in my soul since baseball season has been postponed. And as a result, I've thought more about tigers and big cats more than I ever have in my life. I know ALL about Carol Baskins and am fully on board for a spin-off centering on locating her lost husband. I've googled "is it really legal to own a tiger in a residential area?" Without baseball in April, I am barely hanging in there (kinda like Joe Exotic's eyebrow ring). So, I am filling the sports-sized hole by using baseball stats in Power BI to demonstrate pulling data from multiple tables and consolidating it into one table.  Some of the data we want to consolidate also has to have some aggregations (which is fancy for "calculations") performed on it.  In this demo I will attempt to break down what is really going on

Create A Record Without A Form In Power Apps Using PATCH

 In Power Apps, forms are great to use to submit data to be recorded in your data source.  They do not take long to set up and the functions used to submit the data are fairly simple.  This simplicity, however, can come at a cost.  The cost of using a form is you don’t have a lot of design control in terms of layout and design.  If you don’t like the rigid structure of forms and want more freedom, then I’ve got the fix for you.  You need to become acquainted with the Patch function.   The Patch function allows you to update or create a new record in your data source.   The Patch function requires you to identify your data source, decide if you want to update or create a record, and then point to your controls on the app that contains the data you are submitting.   The coding is a little more involved compared to SubmitForm(FormName) that you use on forms.   The payoff, though, for learning a little more advanced code is you get complete design freedom for your data input controls.