SUMX in Power BI: Comprehensive Guide to DAX Calculations

Published on Jan 03,2025 24 Views

Investigating the point where knowledge and passion converge, Come along with me... Investigating the point where knowledge and passion converge, Come along with me on an exploration journey where words paint pictures and creativity is fueled...

Microsoft created Power BI, a quickly expanding business intelligence (BI) tool and data visualization program, to revolutionize how businesses use data analytics to address business issues. Power BI’s extensive modeling, real-time high-level analytics, and custom development simplify working with data. You will often need to work around several features to get the most out of business data with Microsoft Power BI. This blog will walk you through SUMX Power BI Functions, one of these traditional and significant functions.

Formulae and expressions in Power BI are created using a set of functions, operators, and constants called Data Analysis Expressions (DAX). One such built-in Power BI mathematical DAX function that returns the sum of expressions from a table is called DAX SUMX. The iteration function SUMX Power BI performs a row-by-row calculation by the provided expression.

To understand the foundation, let’s start by exploring what SUMX is and how it operates in Power BI.

SUM vs SUMX in Power BI | DAX in Power BI | Edureka


In this video on SUM and SUMX in Power BI , we explore the fundamentals of these powerful DAX functions and their differences.

What is SumX in Power BI?

Power BI comes with a built-in function called SumX that lets users do sophisticated calculations using their data. It functions as an iterator function that computes the sum based on the provided expression row by row. It’s among the most adaptable DAX functions for combining data to produce more precise and perceptive reports.

SumX Power BI can help you improve your data analysis. For instance, you can compare performance and compute averages, totals, and percentages. It’s a flexible feature that enables you to write unique formulas for a range of computations. Additionally, it manages sizable datasets without causing Power BI to crash or perform less quickly.  
Syntax

  • SUMX (Expression, Table)

Table: The table that the function iterates over, or the table expression.

Expression: The statement that is assessed for every table row. Data from the table’s columns is frequently used in this expression.
Return value

  • A decimal number.

Remarks

  • A table or an expression that yields a table is the first argument passed to the SUMX function. The second argument is either an expression that evaluates to a column or a column containing the numbers you wish to sum.
  • An iterator function is the SUMX.
  • The only numbers that are counted are those in the column. Text, logical values, and blanks are disregarded.
  • See ALL and CALCULATETABLE for more intricate formulaic examples of SUMX.
  • This function cannot be used in row-level security (RLS) rules or calculated columns in DirectQuery mode. 

Example
The following example first filters the table, InternetSales, on the expression,

Sales Amount = SUMX ( 'Details (1)', 'Details (1)'[Quantity] * 'Details (1)'[Amount])

This DAX formula determines the sales amount by repeatedly reviewing each row in the ‘Details (1)’ table, multiplying the Quantity column by the Amount column, and adding up the results.

Breakdown:

SUMX: Computes each row individually, then adds up the results.

The table to iterate over is specified by “Details (1).”

The quantity is ‘Details (1)’ * ‘Details (1)'[Amount]: The formula for each row’s computation (quantity multiplied by Amount). 

Now that we know what SUMX is, let’s delve into why it’s such a powerful function and when it’s most beneficial to use.

Why is the SUMX Function used in Power BI?

The purpose of the Power BI SUMX function was to perform calculations across a table or dataset row by row. It can, therefore, perform more intricate aggregations than a summation. For every row, it will evaluate an expression, which could be as simple as multiplying the values of two columns and then combining the outcomes. This is highly helpful for revenue calculations (quantity x price, for example) or any dynamic measures that need row-by-row calculations before summation.  

Next, let’s break down the mechanics of SUMX to see how it processes data row by row for customized calculations.

How SUMX Works in Power BI?

It is quite simple to use the SUMX Power BI function. A sample “Sales Amount” is taken into consideration for this demonstration. Data about Quantity and the cost price of Amount are included in the dataset (1). The SUMX DAX function can be used to determine the total sales value. To accomplish this, take the actions listed below. 

Here’s the sample dataset(1), if you need this dataset ping us in the comment we will provide you 

The table contains three columns: Details (1), Quantity, and Amount. You can now upload this dataset to Power BI.

  • To do so, go to the “Home” menu and click on the “Get Data” tab.
  • Since our data is in Excel, select the “Excel” or “Text/CSV” option.

  • Click on “Load” and name the table “Details (1)”.
  • To arrive at each row calculation, apply the SUMX Power BI function in “New Measure“. Right-click on the table and select “New Measure

 

  • Name this new measure “Sales Amount.”
  • Open the SUMX function and provide the table name and the expression to be evaluated. The table name is “Details (1),” and you need to multiply Quantity with Amount to get the Sales Amount.
  • Close the bracket and press “Enter” to get the result.

The “Table” visual from the visualization list should now be inserted into the “Report” tab to visualize the results.

Now, come back to the “Report” tab.

 

  • Insert the “Table” visual from the “Visualizations” list.

  • Drag and drop “Category” and “Sale Amount” to get the summary table.

 

I hope you now understand how the SUMX Function works in Power through the step-by-step

SUMX Best Practices

Take into account some of these best practices when utilizing Power BI’s SUMX function:

  • Before using SUMX, make sure your data model is properly organized.
  • Relationships and model schema must also be properly defined for Power BI reports to be accurate and optimized.
  • SUMX cannot be used in calculated columns or row-level security rules in DirectQuery mode.
  • Make SUMX’s expressions as straightforward and effective as you can. Only do calculations that are simple enough because they will slow down performance, especially when dealing with big datasets.
  • Pay attention to context changes and how they may impact your function’s outcomes.
  • SUMX only takes numbers into account. Text, logical values, and blanks are disregarded. 

Moving on, let’s compare SUMX with other Power BI functions to understand its unique strengths and use cases.

SUMX vs Other Functions

It can be a little confusing to know which function to use and when because some of them are similar to SUMX. Let’s dissect two of the most perplexing functions.

  • SUM vs SUMX

SUM is the best example of an aggregator engine function. The result is obtained by adding (or aggregating) all of the values in a single column. Only values from the column to which SUM is applied can be added. Because SUM and other aggregator functions don’t understand the concept of a row, they can’t do row-by-row analyses.

Nevertheless, SUMX is an iterator function, which means that after the evaluation is finished, it iterates through each row of the provided table to create a new piece of logic. Iterator engine functions (other iterator functions include COUNTX, RANKX, PRODUCTX, etc.) can perform row-by-row calculations because they are aware of the rows in a table, unlike aggregators.

  • SUMX vs CALCULATE

One of the most potent DAX functions, CALCULATE, changes the filter context on a calculation. The CALCULATE function has the following syntax:

Calculate (Filter1, Filter2, Expression, etc.)

When you need to perform calculations under different filter conditions than the ones currently applied to the report or model, CALCULATE is the best option. SUMX, however, is used for row-level computations followed by an aggregation.

In complex situations, we can combine CALCULATE with other functions, such as SUMX. For instance, you could utilize CALCULATE to specify a particular filter context in which SUMX carries out its row-level computations and aggregation. 

  • AVERAGE/MAXX/MINX vs SUMX

Regarding SUMX, AVERAGEX/MAXX/MINX: These functions (AVERAGEX, MAXX, MINX, etc.) likewise loop through rows and carry out aggregations rather than additions, just like SUMX.

For instance, AVERAGEX(Sales, Sales[Quantity]*Sales[Price]) determines the revenue average for each row. 

Sales, Sales[Price]*Sales[Quantity]) MAXX: “Find the maximum of the revenue row” -wise. 

It is employed for results summarization.

To clarify further, let’s explore the key differences between SUM and SUMX, two commonly confused functions.

How is SUM Power BI Different From SUMX Power BI?

For many data professionals, knowing the distinction between SUM and SUMX Power BI functions can be a game-changer. Understanding how to use these features properly can offer the chance to delve deeper into unprocessed data and easily extract useful insights. Effective use of them will simplify your data analysis and enable your data to reach its maximum potential. Despite having a similar appearance, the two functions are very different.
SUM is a straightforward aggregation function in Power BI that sums up each value in a column. There are no row-wise computations involved; it operates directly on the column.

SUMX, on the other hand, is an iterator function that lets you calculate each row separately before adding up the results. A table expression is needed, and it evaluates the expression for every row before adding up the outcomes. When you need to perform a calculation (like multiplying values) before adding them up, SUMX comes in handy.

Example of SUM

 

SUM: This function adds up all the values in a specified column.

‘Shop Details'[Sales]: Refers to the Sales column in the Shop Details table. This column contains individual sales amounts for each row.

How it Works:

  • Power BI scans the Sales column in the Shop Details table.
  • It adds up all the numerical values in this column.
  • The result is a single aggregated value representing the total sales.

Example of SUMX

 

  • SUMX: An iterator function that evaluates an expression for each row of a table.
  • ‘Shop Details’: The table being iterated over.
  • ‘Shop Details'[Quantity] * ‘Shop Details'[Profit]: The custom calculation performed for each row. This multiplies the Quantity and Profit values for each row.

How it Works:

  1. Row-by-Row Calculation: For each row in the Shop Details table, it calculates Quantity * Profit.
  2. Summing the Results: After calculating the product for all rows, SUMX adds these results together to return the total.

Handling of the Context

  • SUM belongs to the aggregator function and does not contain any extra filtering for data analysis. While SUMX PowerBI runs with an iterator function and gives you the data analysis of each row in the table.

Flexibility

  • SUM is restricted to the aggregation of data within a single column. On the other hand, SUMX offers multiple data analyses of each row in the table. It can also apply the filters as well.

Use Cases

  • SUM can be the perfect choice for simple aggregative calculations within a single column like totals or sub-totals. SUMX is the best for the row calculations or applying filters on the data.

Performance

  • Due to its simplicity, SUM is generally faster and less resource-intensive, while SUMX may be more resource-intensive due to the additional row-by-row calculations.

Now, let’s highlight some common mistakes to steer clear of when working with SUMX to ensure accuracy and performance.

Mistakes to avoid when utilizing SUMX Power BI

  • In Power BI, the most common errors in the use of the Sumx function include but are not limited to, the incorrect use of data types, references to nonexistent columns or tables, and wrong syntax. It is advisable to master DAX syntax and function principles before you venture into complex calculations, measures, or formulas.
  • Another common mistake when using Sumx in Power BI is misuse of the filter context. It is necessary to realize the difference between row context and how it affects the calculation’s outcome.
  • From a performance point of view, the effects of using Sumx in Power BI must also be considered. The Sumx function in Power BI may be resource-hungry, especially in the case of very large datasets. Optimizing your data model and using other DAX functions like Calculate and Summarise is the best solution for achieving high performance and low error occurrence.
  • Use proper data types, avoid columns or tables that do not exist, and remember that wrong syntax is also a common mistake when using Sumx in Power BI. However, it can prove highly advisable to know and understand DAX syntax and function principles before doing any complex calculations or measures.
  • Another typical mistake when using Power BI with Sumx is getting the filter context wrong. Learn the distinction between row context and how each contributes to the results of your computations.
  • Performance from using Sumx in Power BI needs to be considered. The Sumx function in Power BI may consume several resources, more so in cases of very large data sets. For optimum results and minimum chances of error, optimize your data model and make use of other DAX functions, such as Calculate or Summarize.

Next, let’s summarize the advantages of using SUMX in Power BI and how it can enhance your reporting.

Benefits of using SUMX

  • Versatility Because SUMx can be used with any table or column, it provides flexibility in computations.
  • Dynamic Calculations By using filters or conditions, SUMX enables you to calculate specific values.
  • More Complex Analysis

Combining SUMX with other DAX functions allows you to perform more complex calculations and gain a deeper comprehension of your data.

  • Sumx’s Advantages Over Other Power BI Aggregation Features

Compared to Power BI’s current aggregation features, Sumx Power BI offers a more versatile approach to working with complex data. It can perform calculations over filters and determine multiple values based on table expressions.

To get the most out of SUMX, let’s now explore performance optimization tips for handling large datasets and complex calculations.

Recommendation for Maximizing Performance While Utilizing Power BI’s Sumx

When using Sumx Power BI, keep the following tips in mind to optimize performance:

  • If possible, simplify the Sumx function and use it less frequently.
  • Keep the table of columns where the data is being aggregated to a minimum.
  • Use proactive caching and computation groups to avoid time-consuming data processing.
  • Employing suitable data modeling will help you process less data. 

As we near the conclusion, let’s cover additional tips and tricks that can help you master SUMX like a pro.

Tips and Tricks for Using SUMX in Power BI

First Tip: Use DAX variables for intricate computations.

Complex computations can be made simpler with Power BI’s DAX variables:

  • Choose the calculation that needs to be performed.
  • Declare a variable using the VAR keyword, then assign a name to it.
  • To assign the variable the outcome of a calculation or expression, use the “=” symbol.
  • Use the variable instead of the original expression in the intended calculation or formula.
  • By utilizing DAX variables, you can:

Improve the formulas’ readability and maintainability.

Make use of computation more than once.

Break up complex calculations into smaller, easier-to-manage pieces.

Second Tip: Use SUMX in conjunction with other DAX functions for more advanced analysis.

  • To enhance Power BI’s analytical capabilities, combine the SuMX function with other DAX functions. To begin, take these actions:
  • Select the DAX functions that best meet your analysis requirements.
  • Use the SUMX function to iterate over a table or column and compute the desired result.
  • Combine the SUMX function with other DAX functions, such as AVERAGE or COUNTX, to produce more intricate computations.

Finally, we’ll wrap up with a summary of the key points discussed and how SUMX empowers your Power BI analyses.

Conclusion

Microsoft’s business intelligence tool, Power BI, is used by data professionals worldwide to analyze data from various sources and produce visually appealing charts, dashboards, and reports based on user-specified data. Power BI’s data import, transformation, and visualization features make it easy to create reports. To get the most out of raw data, one must be familiar with key DAX functions like SUMX Power BI.

Still have questions? Let’s address some frequently asked questions about SUMX to clarify common doubts and challenges.

FAQs

1. What is the difference between SUMX and sum DAX?

Differences are:

SUM: It is as simple as a direct summation of values in one single column; with that, it does not have to calculate row by row.

Example: SUM (Sales[Revenue]), which adds total values in the Revenue column.

SUMX: It iterates through the table row by row, evaluates a customized expression for each row, and then sums the values; it is useful in dynamic row-level calculations.

Example: SUMX (Sales, Sales[Quantity] * Sales[Price]). It calculates revenues (Quantity * Price) for individual rows and then sums them all up.

2. What is the use case of the sumx function?

SUMX is an iterator function, meaning that it iterates through each row of the given table to develop a new piece of logic after the evaluation is complete. Unlike aggregators, iterator engine functions are aware of the rows in a table, allowing them to perform row-by-row calculations (other iterator functions include COUNTX, RANKX, PRODUCTX, etc.).

3. What is a DAX formula in Power BI?

DAX formula(Data Analysis Expressions) refers to the collection of functions, operators, and values that are used as per the requirement for performing calculations and returning results in a data model within a scope of use. The formula in DAX will create calculated columns, calculated measures, and calculated tables that can be done dynamically using a calculated field to analyze and get insight from it. It helps to manipulate, aggregate, and define business logic for representation purposes.

4. How many DAX formulas are there?

There are more than 250 DAX functions in Power BI organized into different categories such as:

  • Aggregation Functions: SUM, AVERAGE, COUNT, etc.
  • Date and Time Functions: DATE, DATEDIFF, TODAY, etc.
  • Filter Functions: FILTER, CALCULATE, ALL, etc.
  • Logical Functions: IF, SWITCH, AND, OR, etc.
  • Text Functions: CONCATENATE, LEFT, RIGHT, etc.
  • Mathematical Functions: ABS, ROUND, SQRT, etc.
  • Statistical Functions: MEDIAN, STDEV, VAR, etc.
  • Information Functions: ISBLANK, ISNUMBER, etc.
  • Relationship Functions: RELATED, RELATEDTABLE, etc.
  • Time Intelligence Functions: TOTALYTD, SAMEPERIODLASTYEAR, etc.

All these functions are combined to come up with very strong calculations and measures in Power BI.

The SUMX Power BI function was covered in this blog, along with an introduction to Power BI. Before concluding, the article also distinguishes between Power BI SUM and SUMX functions. Power BI’s user-friendly, interactive, and intuitive services increase the efficiency of business analysis. Furthermore, it can be not easy to analyze and visualize your data when you load it into Power BI from a data warehouse.  

If you are interested in advancing your skills and your career prospects as a Power BI developer, then you should explore the latest courses and Training programs. We recommend you take up the Microsoft Power BI Certification Training: PwC Academy offered by Edureka. The Edureka’s Power BI certification course by PwC offers dual certification in business intelligence. The training is live instructor-led and provides hands-on experience in real-time projects. It prepares you for the official PL-300 exam and offers simulated real-world scenarios.

Upcoming Batches For Microsoft Power BI Certification Training: PwC Academy
Course NameDateDetails
Microsoft Power BI Certification Training: PwC Academy

Class Starts on 11th January,2025

11th January

SAT&SUN (Weekend Batch)
View Details
Microsoft Power BI Certification Training: PwC Academy

Class Starts on 13th January,2025

13th January

MON-FRI (Weekday Batch)
View Details
Microsoft Power BI Certification Training: PwC Academy

Class Starts on 1st February,2025

1st February

SAT&SUN (Weekend Batch)
View Details
Comments
0 Comments

Join the discussion

Browse Categories

webinar REGISTER FOR FREE WEBINAR
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP

Subscribe to our Newsletter, and get personalized recommendations.

image not found!
image not found!

SUMX in Power BI: Comprehensive Guide to DAX Calculations

edureka.co