How to create Power BI Calculated Table? : Simplified 101

|

power bi calculated table: FI

Microsoft’s Power BI is a technology-driven Business Intelligence tool for analyzing and visualizing raw data to present actionable data. It brings together Business Analytics, Data Visualization, and best practices to assist organizations in making data-driven decisions. Because of the capabilities of the Power BI platform, Gartner named Microsoft the Leader in the “2019 Gartner Magic Quadrant for Analytics and Business Intelligence Platform” in February 2019.

The CALCULATETABLE Function switches the context in which the data is filtered and evaluates the expression in the new context. Any existing filters on each column used in a filter argument are removed and replaced with the filter used in the filter argument.

This article talks in detail about the DAX CALCULATETABLE Function and how it is used to create Power BI calculated tables. It also gives an introduction to Power BI and DAX.

Table Of Contents

What is Power BI?

power bi calculated table: power bi logo
Image Source

Power BI is a proprietary Business Intelligence tool designed for seamless Data Analytics and Data Visualization. It is a part of the Microsoft Power Platform. Power BI is one of the common tools used by organizations for analyzing their business data construct reports. 

It comes with a collection of various in-built software services, apps, and connectors that deeply integrates with data sources to deliver immersive visuals, interactive reports, and generate insights. Power BI uses its advanced charts, graphs, and other visuals included with Machine Learning to easily extract valuable information out of data.

Power BI can also read data from XML files, CSV files, JSON format files, and even web pages, then convert raw data into interactive insights. It is available for Desktop, mobile, and on-premise servers. Users can create and share their reports with other Power BI users within the organization or partner companies. It can be used to create Power BI calculated tables and calculated columns.

Power BI Calculated tables were first introduced in Power BI Desktop’s September 2015 update. The name says it all: these are tables that have been calculated. Because these are in-memory tables, they are calculated using DAX. Power BI Calculated tables have numerous advantages, including the ability to use them for role-playing dimensions (for example having more than one date dimension in a model).

Key Features Of Power BI

Some of the main features of Power BI are listed below:

  • Supports API Integrations: Power BI allows developers to easily integrate with other applications and embed dashboards into other software using sample codes and APIs.
  • Custom Visualization: Power BI offers custom visualization libraries support that allows users to visualize complex data with ease.
  • AI Support: Users can easily perform Data Analytics using Artificial Intelligence. With the built-in AI support, users can prepare data, build Machine Learning models, and gain insights.
  • Modeling View: With the help of Modeling View, Power BI users can slice and divide the complex data into simpler ones that help in better understanding the data, separate diagrams, and multi-select objects.
  • Easy Sharing: Power BI makes it easier for users to easily share their reports within teams, or organizations ensuring full data protection.
  • Hybrid Development: Power BI easily integrates with many 3rd party connectors, applications, and services widely used by organizations that allow users to connect to various data sources.

Click here to know more about Power BI.

Simplify the Power BI Visualization Process with Hevo’s No-code Data Pipeline

Hevo Data, a No-code Data Pipeline helps to load data from any data source such as Power BI, Databases, SaaS applications, Cloud Storage, SDKs, and Streaming Services and simplifies the ETL process. It supports 150+ data sources and is a 3-step process by just selecting the data source, providing valid credentials, and choosing the destination. Hevo not only loads the data onto the desired Data Warehouse but also enriches the data and transforms it into an analysis-ready form without having to write a single line of code.

Get Started with Hevo for Free

Its completely automated Data Pipeline offers data to be delivered in real-time without any loss from source to destination. Its fault-tolerant and scalable architecture ensure that the data is handled in a secure, consistent manner with zero data loss and supports different forms of data. The solutions provided are consistent and work with different BI tools as well.

Check out why Hevo is the Best:

  • Secure: Hevo has a fault-tolerant architecture that ensures that the data is handled in a secure, consistent manner with zero data loss.
  • Schema Management: Hevo takes away the tedious task of schema management & automatically detects the schema of incoming data and maps it to the destination schema.
  • Minimal Learning: Hevo, with its simple and interactive UI, is extremely simple for new customers to work on and perform operations.
  • Hevo Is Built To Scale: As the number of sources and the volume of your data grows, Hevo scales horizontally, handling millions of records per minute with very little latency.
  • Incremental Data Load: Hevo allows the transfer of data that has been modified in real-time. This ensures efficient utilization of bandwidth on both ends.
  • Live Support: The Hevo team is available round the clock to extend exceptional support to its customers through chat, email, and support calls.
  • Live Monitoring: Hevo allows you to monitor the data flow and check where your data is at a particular point in time.
Sign up here for a 14-Day Free Trial!

What is DAX?

DAX (Data Analysis Expressions) is a Power BI functional language that uses a collection of Functions, operators, and constants to solve basic calculation and Data Analysis problems. Analysis Services, Power BI, and Power Pivot in Excel all use Data Analysis Expressions (DAX) as a formula expression language. In tabular data models, DAX formulas include functions, operators, and values that can be used to perform advanced calculations and queries on data in related tables and columns.

The DAX language was designed specifically for working with data models using formulas and expressions. Microsoft Power BI, Microsoft Analysis Services, and Microsoft Power Pivot for Excel are all products that use DAX. Tabular is the internal engine that runs all of these products.

Working in DAX improves the user experience by implementing functionalities such as Data Visualization, Data Importing, and Manipulation. Basic dashboard knowledge is sufficient for creating standard reports, but DAX is required to create sophisticated and insightful reports. The reports generated are highly intuitive and discerning, thanks to the numerous commands and measures that can be used under the DAX syntax. The calculated table formula in Power BI must return a table object. An existing model table can be duplicated with the simplest formula.

DAX is a formula language used in Power BI Desktop to work with relational data. DAX comes with a library of over 200 Functions, operators, and constructs, giving you a lot of freedom when it comes to creating formulas to calculate results for almost any Data Analysis task. Power BI Calculated tables are ideal for intermediate calculations and data that you want to keep in the model rather than calculating on the fly or as query results. For example, you could join two tables together using a union or a cross join.

It’s understandable to wonder why DAX is so important to master in order to work efficiently with Power BI. Well, as we’ve seen in previous tutorials, creating reports in Power BI using the data importing, transforming, and visualizing features is a breeze. To create a decent report with all of the available data, a user must have a basic understanding of Power BI Desktop. However, if you want to take your Power BI reports to the next level, you’ll need DAX. Using DAX you can create Power BI calculated tables.

Some of the Functions that either return a table or manipulate one that already exists in DAX are ADDCOLUMNS, CROSSJOIN, CURRENTGROUP, DATATABLE, EXCEPT, FILTERS, DISTINCT table, Table Constructor, UNION, VALUES, etc. 

A DAX Function is a predefined formula that performs calculations on input values. A column reference, numbers, text, constants, another formula or Function, or a logical value such as TRUE or FALSE are all examples of arguments in a Function that must be in a specific order. Every Function does something different with the values in an argument. In a DAX formula, you can include multiple arguments.

To add a Power BI calculated table to your model, you can use a DAX formula. To create a new Power BI calculated table, the formula can duplicate or transform existing model data.

The majority of the time, you create tables by importing data from an external data source into your model. Power BI Calculated tables, on the other hand, allow you to create new tables based on data that has already been loaded into the model. Instead of querying and loading values into your new table’s columns from a data source, you define the table’s values using a DAX formula.

Key Features Of DAX 

  • Standard Functionality like Formulas in Excel: SUM, SUMIF, VLOOKUP, and other Excel formulas are familiar to most users. In Power BI, DAX provides similar formulas and additional functionality for all types of calculations. Nonetheless, Excel formulas operate on cells, whereas Power BI operates on tables and columns. For more information on each of the more than 200 Functions available in DAX.
  • Simplicity: There is a learning curve to grasp the concepts and ideas of DAX, but it is doable, and after a short period, you will notice a structure and logic. It’s very simple once you’ve grasped these fundamental concepts.
  • Solves Business Problems: Whenever you have a data problem in Power BI, there’s a good chance DAX will solve it. In DAX, you can perform a wide range of calculations, and you can always search for something DAX using a search engine or the Power BI community.
  • Improves the Data Model: You must look after your underlying data model if you use DAX. Data Modeling is sometimes regarded as an art form, but once you grasp the fundamental concepts, such as dimensional modeling and star schemas, your data model’s maintainability will greatly improve.
  • Time-intelligence Functions: These Functions aid in the creation of calculations involving calendars and dates. This allows you to make meaningful comparisons between periods (e.g. calculations of year-to-date, comparison with last period, previous month, etc.).
  • Calculated Columns: Eventually, you’ll be in a situation where your data lacks a field that you require. Calculated columns can be used to define the value of a column, for example, by combining text values or calculating a numeric value from other values.

What is CALCULATETABLE FUNCTION?

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. Power BI Calculated tables come at a price: they expand the model’s storage space and can slow down data refresh. The reason for this is that when calculated tables have formula dependencies on refreshed tables, they recalculate. External data cannot be connected to a Power BI calculated table; instead, you must use Power Query.

It uses a modified filter context to evaluate a table expression.

The following is the syntax for the CALCULATE TABLE Function:

CALCULATETABLE(<expression>[, <filter1> [, <filter2> [, …]]])

The parameters are the following: 

TermDefinition
expressionThe table expression is to be evaluated.
filter1, filter2,…(Optional) Boolean expressions or table expressions that define filters, or filter modifier functions.

A model table or a table-returning Function must be used as the first parameter.

There are several types of filters:

  • Boolean filter expressions: An expression that evaluates to TRUE or FALSE is called a Boolean expression filter. They must follow the following guidelines:
    • They are unable to refer to measures.
    • They are unable to use a CALCULATE Function that is nested.
    • They can only refer to one column at a time.
  • Table filter expressions: A table expression filter works by filtering a table object. It could be a reference to a model table, but it’s more likely a table object returned by a Function. The FILTER function can be used to apply complex filter conditions that aren’t defined by a Boolean Filter expression, such as those that aren’t defined by a Boolean Filter expression.
  • Filter modification Functions: You can do more with Filter Modifier Functions than just add filters. They give you more options when it comes to changing the filter context.
FunctionPurpose
REMOVEFILTERSRemove all filters, or filters from one or more columns of a table, or from all columns of a single table.
ALL, ALLEXCEPT, ALLNOBLANKROWRemove filters from one or more columns, or from all columns of a single table.
KEEPFILTERSAdd filter without removing existing filters on the same columns.
USERELATIONSHIPEngage an inactive relationship between related columns, in which case the active relationship will automatically become inactive.
CROSSFILTERModify filter direction (from both to single, or from single to both) or disable a relationship.

The ALL Function and its variants work as both filter modifiers and table-object-returning Functions. If your tool supports the REMOVEFILTERS Function, it’s preferable to use it to remove filters.

  • Some of the things to consider while using CALCULATETABLE FUNCTION are:
    • The CALCULATETABLE Function modifies the filter context to evaluate filter expressions when they are provided. When the filter expression is not wrapped in the KEEPFILTERS Function, there are two possible standard outcomes for each filter expression:
      • In order to evaluate the expression, new filters will be added to the filter context if the columns (or tables) aren’t in the filter context.
      • Existing filters will be overwritten by the new filters when evaluating the CALCULATETABLE expression if the columns (or tables) are already in the filter context.
    • When used in calculated columns or Row-Level Security (RLS) rules, this Function is not supported when using DirectQuery mode.

How to create Power BI Calculated Table?

1. Power BI Calculated Tables: Basic Use of CALCULATETABLE Function

To see the basic use of CALCULATETABLE Function to create Power BI calculated tables follow the steps:

  • Step 1: You create a table called CalCtable which is a Power BI calculated table to filter the records for quantity >1.
CalCtable = CALCULATETABLE(TransactionHistory,TransactionHistory[Quantity] >1)
Image Source

When you commit a DAX function, the data model creates a Power BI calculated table called CalCtable.

This table is a copy of the actual table TransactionHistory, but it only contains products with a quantity greater than one.

  • Step 2: You must drag Table Fields into a table visual to see all products with quantities greater than one.
  • Step 3: You can also compare the result sets of both tables; you’ll notice that CalCtable only contains products with a quantity value greater than 1.
  • As a result, you can sort Power BI calculated table records using the CALCULATETABLE function based on any condition.

2. Power BI Calculated Tables: Using CALCULATETABLE Function with Summarize Function

You can create Power BI calculated tables with the use of CALCULATETABLE Function with Summarize Function. You can see this in the example below:

CALCULATETABLE returns a table based on filter conditions. It returns all columns of the base table, but if you only want to see certain columns, you can use the SUMMARIZE Function within CALCULATETABLE. Follow the steps below to see how it is done:

  • Step 1: Modify the DAX calculation above to return only the ProductID, Quantity, and TransactionDate columns.
CalCtable =
CALCULATETABLE (
SUMMARIZE (
TransactionHistory,
TransactionHistory[ProductId],
TransactionHistory[Quantity],
TransactionHistory[TransactionDate]
),
TransactionHistory[Quantity] > 1
)
  • Step 2: As shown below, after you commit the DAX, you will only see the columns that you want to see.

3. Power BI Calculated Tables: Using CALCULATETABLE Function within Measures

You can also create Power BI calculated tables using the CALCULATETABLE Function within a Measure , rather than creating a separate filtered table.

SumofQuantity>1 =

SUMX(
CALCULATETABLE (
TransactionHistory,
TransactionHistory[Quantity] > 1
),TransactionHistory[Quantity])

Follow the steps to see how to create Power BI calculated tables using CALCULATETABLE Function within Measures:

  • Step 1: Drag the measure into the Card Visual after you’ve committed the DAX.
  • Step 2: As you can see, it returns a Total Quantity Sum of Products with a quantity greater than one, which is 21 in this case.

Conclusion

This article talks about the DAX CALCULATED TABLE Function and how it is used to create Power BI Calculated Tables. It also gives a brief description of Power BI and DAX.

Visit our Website to Explore Hevo

Power BI is a great tool for performing Data Analytics and Visualization for your business data. However, at times, you need to transfer this data from multiple sources to your PowerBI account for analysis. Building an in-house solution for this process could be an expensive and time-consuming task. Hevo Data, on the other hand, offers a No-code Data Pipeline that can automate your data transfer process, hence allowing you to focus on other aspects of your business like Analytics, Customer Management, etc.

This platform allows you to transfer data from 150+ sources to BI tools like Power BI, and Cloud-based Data Warehouses like Snowflake, Google BigQuery, Amazon Redshift, etc. It will provide you with a hassle-free experience and make your work life much easier.

Want to take Hevo for a spin? Sign Up for a 14-day free trial and experience the feature-rich Hevo suite first hand.

Harshitha Balasankula
Former Marketing Content Analyst, Hevo Data

Harshita is a data analysis enthusiast with a keen interest for data, software architecture, and writing technical content. Her passion towards contributing to the field drives her in creating in-depth articles on diverse topics related to the data industry.

Deliver smarter, faster insights with your unified data