How to Use SUMX() Function in Power BI?

This Power BI tutorial will help you work with the Power BI SUMX function.

We recently worked on a Power BI Report where the SUMX function helped calculate all the sales values in a data set.

This tutorial will show the SUMX measure in Power BI and a real-time example of how to use SUMX() function in Power BI.

SUMX() in Power BI

The SUMX function in Power BI is used to calculate the sum of an expression for each row in a table. This function processes each row at a time, applying the specified calculation. The return value of the SUMX function is a single value of any type.

Power BI SUMX function syntax:

SUMX(<Table>, <Expression>)

Where:

  • Table = This is the name of the table on which you want to apply the SUMX function.
  • Expression = Here, you need to specify the expression or equation the SUMX function will use to calculate each row of the designated table.

How to Use SUMX() Function in Power BI

This example shows how to create and use the SUMX function in Power BI.

Here, I have a SharePoint list (Financial Sample) that contains below columns with various data types:

ColumnData Types
SegmentSingle line of text
ProductSingle line of text
Units SoldNumber
Sales PriceCurrency
sumx measure power bi

Let’s create a measure in Power BI to assess the functionality of the SUMX function. So, we will evaluate the total sales using SUMX as a Measure in Power BI. To do this, follow the below steps.

1. Open Power BI Desktop and load the data. Then, you see data in the Data pane.

How to Use Sumx in Power BI

2. Under the Home tab, click on the New measure.

How to Use SUMX Power BI Function

3. In the formula bar, click the below expression. Then click Commit.

Total Sales = SUMX(
		'Financial Sample',
		'Financial Sample'[Units Sold] * 'Financial Sample'[Sale Price]
	)

Where:

  • Total Sales = Name of the measure
  • Financial Sample = Name of the Table
  • Units Sold = Name of the Column
  • Sale Price = Name of the Column
power bi sumx measure

4. Under the Home tab, expand Visual gallery(black box) -> Click the Table visual.

How to Implement the SUMX Function in Power BI

5. Then, using the +Add data option, add the Product, Units Sold, Sale Price, and Total Sales(Measure) into the Columns in the Table visual.

How to Use SUMX DAX function in Power BI

This is how to use SUMX() in Power BI.

Power BI SUMX with IF statement

This example shows how to use a Power BI SUMX with an if statement.

The Power BI SUMX function iterates through the rows of a table and calculates a specified expression for each row. Combined with an IF statement, you can include or exclude values conditionally.

Suppose you have a Sales table with columns like Product, Quantity, and Price, and you want to calculate the total sales only for products with a quantity greater than 5. You can use the SUMX function with an IF statement. To do this, follow the below steps.

1. Our table looks like the below screenshot.

Power BI Creating a measure SUMX with IF

2. Under the Home tab, click on the New measure.

How to Use SUMX Power BI Function

3. In the formula bar, click the below expression. Then click Commit.

TotalSalesQuantityGreaterThan5 = SUMX(
		'SalesTable',
		IF(
			'SalesTable'[Quantity] > 5,
			'SalesTable'[Quantity] * 'SalesTable'[Price],
			0
		)
	)

Where:

  • TotalSalesQuantityGreaterThan5 = Name of the measure
  • SalesTable = Name of the Table
  • Quantity = Name of the Column
  • Price = Name of the Column
Power BI SUMX function

4. Under the Home tab, expand Visual gallery(black box) -> Click the Table visual.

How to Implement the SUMX Function in Power BI

5. Then, using the +Add data option, add the Product, Quantity, Price, and TotalSalesQuantityGreaterThan5(Measure) into the Columns in the Table visual.

What is SUMX() in Power BI

You can use a Power BI SUMX with an if statement.

Conclusion

The SUMX function in Power BI is used to calculate the sum of an expression for each row by row.

This tutorial taught us what the Power BI SUMX() measures and how to use the SUMX() in the Power BI measure. Additionally, we explained the Power BI SUMX function with an if statement.

Furthermore, you may like some more Power BI tutorials: