Skip to main content

Summarize in DAX

Let's consider a situation where you have one big fact table and you need to create several tables out of it using different columns. The most obvious way is to do it in the backend but it can be time-consuming. What if we can do the same in DAX itself without going back to the source. The solution is quite simple and DAX calls it "Summarize". 

It's quite evident what this function does from the name. You guessed it right!!!! It gives a summary of the fact table based on your selection of fields. To get a better grasp of this function we will take a couple of use cases. We are considering Sample Superstore data and the only fact table is "SampleSuperstore". I want to explore only the geographical data and associated quantity and profit with every city. 

First, we need to create a new table {you can do so by going to Modelling and there in calculations, you can find a new table}. Once you select a new table you have to provide a DAX formula before doing so rename your table. 







ProTip- In the above-mentioned image you can arrange the order of columns in the formula itself. Arrange them as per your need. Also, if you critically observe we have provided different names for quantity as units sold. As it is text it needs to be in double quotes and before the field. 


Isn't it simple?? Now let's move a step further and I am introducing segment also in this table. As an exercise, you can try it on your own. Once you get the segment we need to only showcase data for the Corporate segment. I have to introduce a filter in the DAX but the question is where should we insert it? To know more about filters in DAX refer to one of our old blogs (link)


So now we have our answer. Keep in mind all the parentheses and commas while writing long formulas like the one mentioned above.


Let's add a bit more complexity to it. When you will write summarize you can see there is a function called "Rollup" which is quite an essential part of Summarize family. What is the purpose of this function? It is mainly used to get subtotals and totals inside your table. You will get blank values that highlight the subtotals and totals.

How does it function? We are taking the same formula and we are putting all geographical fields under it. This is how your formula will look once you introduce this function.


To compare we have taken another table with the same formula but without the rollup. And the formula will look like this.


To get a better idea we will go to the visualize mode and take the table and pull all the geographical fields and units sold. Make sure there should not be any summarization happening. We don't need any implicit measures in the table (Implicit measures vs Explicit measures).


We have particularly filtered it for the region "West" and the city "Albuquerque". In the left table, we can see duplicate rows representing the same data. These duplicate rows represent the subtotals.

Protip- Rollup can only be used as part of Summarize. Also, make sure the order you provide to the Rollup function. In our case, I have provided the Postal code as the first base to get our rollup values. Hence you see blanks in the Postal Codes column in the left table.

Summarize is a bit different from Summarize columns as the latter only gives filter context and only be used in particular scenarios but summarize can be used in both filter and row context and hence can be used in almost every scenario.


Thanks for Reading  Let's connect on  LinkedIn. For more such blogs do follow us.

Comments

Popular posts from this blog

Copying Bookmarks from one Power BI report to another

Let's think of a scenario, where you want to copy the bookmarks from one report to another. Most obvious approach is to just do a copy paste of the bookmarks. What's wrong with this approach? This approach only works for all visuals but not for bookmarks and field parameters.  If you are not familiar with basics of bookmarks and field parameters do refer to the beginners guide for bookmarks  and introduction to field parameters . Then how do you copy the bookmarks? Power BI enhanced report format (PBIR) for Power BI Project files (PBIP) will help you in achieving this. Let's check it out, I have 2 reports one contains the bookmark called Bookmarks PBIR Test (origin) and other one is Rolling Average PBIR Test (destination) .  Before we get started, you have to enable Power BI Project save option under preview features. Once enabled, restart Power BI desktop. There is a TMDL icon appearing on the left pane. What is TMDL and what's in it for me? There's a lot of possi...

Playing with Totals in Power BI

Are you a fan of matrix visual in Power BI? If you are as I am, I always struggle to get the correct totals and get something else instead of the totals it can be average. After a lot of research and going over different community posts, finally we have found 3 common scenarios that can elevate your matrix to the next level. To start with, I am using Sample Superstore data. Let's first explain the 3 different scenarios that we will tackle - We  would like  to show both Total Sales and Average Monthly Sales across different categories and different periods. We  would like  to show the Average Sales in the row subtotals and Total Sales in the column subtotals. Last and the  most interesting scenario is to show the Total sales excluding the furniture sales in the row subtotals and total sales in the column subtotals. Let's start by getting the correct totals in a matrix. Generally, if  use  basic Sum, Average... functions in your measures then most likely...

Introduction to Power Ops

Power BI, combined with all external tools, at least the basic ones, can be a perfect BI tool to meet all your needs. Today's blog will focus on another external tool. What?? Not another one!! In my regular practice, I always rely on basic external tools such as DAX Studio, Tabular Editor, and Measure Killer. But what if I say this new tool is a transformer, combining all the basic tools in one place? If you are looking for an introductory guide for the basic external tools, we got you covered.  Beginner's Guide to DAX Studio Advanced Guide to DAX Studio Guide to Measure Killer Yes, you read it right and we will give you an introductory guide to all the functionalities that can be achieved with  Power Ops . Okay, first things first to download Power Ops you can visit their  website  and I would recommend exploring it with one of your reports. You can download the free version. It will be available under the external tools section in Power BI Desktop. Before we move f...