How to create a calculated table of top values in Microsoft Power BI (2024)

How to create a calculated table of top values in Microsoft Power BI (1)

It’s not unusual for Microsoft Power BI designers to look beyond the natural data for insight. When this happens, they have many tools at their disposal: filters, measures, calculated columns and even calculated tables. The latter allows you to perform complex calculations and store the results as part of the model, instead of performing calculations on the fly. The values are in memory and ready to go when needed.

In this tutorial, we’ll create a table based on existing data to extract the top five sales. You can then use that calculated table in visualizations. There are many scenarios where you might want to do so. Later, when building visualizations for that specific purpose, you can use the calculated table instead of the original data that would otherwise require a measure and perhaps a filter to evaluate the same values.

I’m using Power BI Desktop on a Windows 10 64-bit system, but you can also use Power BI Service. To follow along, download the demonstration .pbix file, and then, double-click to open it in Power BI.

SEE: Hiring Kit: Database engineer (TechRepublic Premium)

What a calculated table is in Power BI

Technically, a calculated table in Power BI is an in-memory table created by a Data Analysis Expressions, or DAX, calculation. Calculated tables load into memory, which means they’re always ready. This has benefits, including:

  • Calling in-memory data is more efficient than retrieving the same values from an external data source or recalculating them in real time.
  • You won’t have to retrieve the data again later.
  • The values are always current.

On the downside, calculated tables will increase the size of your .pbix file, but it’s usually a fair trade-off. For now, you might think of a calculated table as a permanently filtered record set. It’s more than that, but that description should clarify its purpose and many benefits.

Now, let’s put all this information to use to create a top five sales table.

How to create a calculated table in Power BI

A list of the top five or so customers is important to most organizations because those customers are likely to represent the largest percentage of all sales. To create a calculated table that returns only the top five customers in the demonstration .pbix file requires two things:

  1. A table of customers with their total sales
  2. A way to filter those to only the top five

Fortunately, DAX handles all of this with the TOPN function (Listing A).

Listing A

Top 5 Sales =

TOPN(5,Sales,[Amount],0)

Figure A shows the resulting table based on the Sales table and the DAX TOPN function used to create and populate this table.

Figure A

How to create a calculated table of top values in Microsoft Power BI (2)

In this case, you don’t even need the CALCULATETABLE function because the TOPN function returns a table. The code won’t always be this simple, but in this case, everything needed is in the same table: Sales.

Here’s how it works:

  • The first argument, 5, restricts the new table to only five records.
  • The second argument, Sales, denotes the table with the values we’re evaluating.
  • The third argument, Amount, denotes the column by which the function sorts the data.
  • The fourth argument, 0, specifies a descending sort.

There’s the top five records. The function creates a new table named Top 5 Sales and populates it with the data in the Sales table, but copies only the first five records in the sorted dataset.

To create the table, do the following:

  1. Click the Table Tools tab.
  2. Click New Table in the Calculations group.
  3. Enter the DAX function into the formula bar, and then, press Enter or click the checkmark to the left.

Once you have the table in place, you can build visualizations on it. As is, it will always display the top five sales from the Sales table, unless you add a filter.

How to use the calculated table in Power BI

You’ll base a visualization on the calculated table, as you would any other. Figure B shows a pie chart that exposes a bit of keen insight — all five top sales are close in value. To build this, click the Pie Chart visualization in the Visualization pane. Then, drag SalesDate to the Legend bucket and Amount to the Values bucket.

Figure B

How to create a calculated table of top values in Microsoft Power BI (3)

Once you have this visualization, you can add filters. Figure C shows a region filter that currently displays only the Central region top sales. To add this filter, open the Filters pane and drag the Region field from the Top 5 Sales table to the Add Data Fields Here bucket.

Figure C

How to create a calculated table of top values in Microsoft Power BI (4)

To apply a filter, simply check one of the regions. The pie chart updates accordingly by displaying only the values for that region. You already know that the values represent the top five. Now, you can easily see those sales by region.

Creating a calculated table is one of many ways to report calculated values based on the natural data. You can reference related tables, specify column data types and formatting, name the table and the columns whatever you like, and base effective visualizations on them.

Subscribe to the Developer Insider Newsletter

From the hottest programming languages to commentary on the Linux OS, get the developer and open source news and tips you need to know. Delivered Tuesdays and Thursdays

Subscribe to the Developer Insider Newsletter

From the hottest programming languages to commentary on the Linux OS, get the developer and open source news and tips you need to know. Delivered Tuesdays and Thursdays

How to create a calculated table of top values in Microsoft Power BI (2024)

FAQs

How do you create a calculated table in Power BI? ›

How to create a calculated table
  1. First, verify the tabular model has a compatibility level of 1200 or higher. ...
  2. Switch to the Data View. ...
  3. Select Table > New calculated table.
  4. Type or paste a DAX expression (see below for some ideas).
  5. Name the table.
  6. Create relationships to other tables in the model.
Dec 9, 2022

How do you show only top 5 values in Power BI? ›

Top 5 Total Revenue By Product Names
  1. To display the Top 5: Select the first Table Visualization.
  2. In the Filters pane to the right, hover the mouse to the Product Names.
  3. Click on the downward facing caret icon.
  4. In the filter type dropdown, select Top N.
  5. Type in 5 into the box.
Nov 7, 2019

How do I create a table from existing data in Power BI? ›

Create a Calculated table from another table in Power BI
  1. Go to the “Modeling” tab in the Power BI Desktop ribbon and select “New Table.”
  2. In the formula bar, enter a DAX expression to define the calculation for the new table. ...
  3. Press Enter to create the calculated table.
May 11, 2021

What is the difference between calculated columns and calculated tables in Power BI? ›

In Power BI, calculated columns, calculated tables, and measures are all used to perform calculations, but they serve different purposes and are applied at different levels within the data model: Calculated Columns: Purpose: Calculated columns are additional columns that you create within a table in your data model.

How do you show top and bottom values in Power BI? ›

TopX = SELECTEDVALUE(Slicer[Value]) (we are taking the values which we created for slicer selection.) If the value of TopRank is equal to or less than the value of TopX, the result will be 1. Similarly, if the value of BottomRank is equal to or less than the value of TopX, the result will be -1.

How do you create a top 10 table in Power BI? ›

To setup Top 10 or Top N filters in Power BI, add a visualization to your dashboard canvas. Then select it and expand the Filters Panel. In the Filters on this visual section, change the Filter Type to Top N and set Show Items to the Top 10 items you would like to see.

How do you create a count table in Power BI? ›

Open your Power BI report and select the data field you want to count. Click on the “Home” tab, then select “New Measure” in the “Calculations” group. In the formula bar, enter “=COUNT(column_name)”, replacing “column_name” with the actual name of the column you want to count.

How to show top 10 in Excel chart? ›

Show the top or bottom 10 items

Select Values Filters > Top 10. In the first box, select Top or Bottom.

What is calculatetable in Power BI? ›

CALCULATETABLE is a DAX Function that evaluates a table expression in a context that has been modified by the given filters. It returns a value table. It is used to create Power BI calculated tables. The table expression to be evaluated is expression>. It is not possible to use a measure as an expression.

How do you create a sum table in Power BI? ›

To utilize the SUM function in Power BI, simply follow these steps:
  1. Open Power BI.
  2. Load the data.
  3. Select the desired column to be summed.
  4. Create a measure.
  5. Utilize the SUM function in the measure.
  6. Add the measure to the report.
  7. Format the measure as needed.

Can you create a calculated column in Power BI? ›

You can create a calculated column that combines values from these two columns. DAX formulas can use the full power of the model you already have, including relationships between different tables that already exist. To create your new column in the ProductSubcategory table, right-click or select the ellipsis ...

Top Articles
Latest Posts
Article information

Author: Carmelo Roob

Last Updated:

Views: 5700

Rating: 4.4 / 5 (45 voted)

Reviews: 84% of readers found this page helpful

Author information

Name: Carmelo Roob

Birthday: 1995-01-09

Address: Apt. 915 481 Sipes Cliff, New Gonzalobury, CO 80176

Phone: +6773780339780

Job: Sales Executive

Hobby: Gaming, Jogging, Rugby, Video gaming, Handball, Ice skating, Web surfing

Introduction: My name is Carmelo Roob, I am a modern, handsome, delightful, comfortable, attractive, vast, good person who loves writing and wants to share my knowledge and understanding with you.