create account

DAX SUM and SUMX Functions by theexcelclub

View this thread on: hive.blogpeakd.comecency.com
· @theexcelclub · (edited)
$61.28
DAX SUM and SUMX Functions
<center>http://theexcelclub.com/wp-content/uploads/2017/02/sumx.png</center> <br/><figure><a href="https://theexcelclub.newzenler.com/courses/master-dax-fundamentals-power-bi-amp-power-pivot" data-elementor-open-lightbox="">
<img src="https://theexcelclub.com/wp-content/uploads/2017/05/1.0.png" sizes="(max-width: 434px) 100vw, 434px" srcset="https://i0.wp.com/theexcelclub.com/wp-content/uploads/2017/05/1.0.png?w=434 434w, https://i0.wp.com/theexcelclub.com/wp-content/uploads/2017/05/1.0.png?resize=283%2C300 283w, https://i0.wp.com/theexcelclub.com/wp-content/uploads/2017/05/1.0.png?resize=410%2C435 410w, https://i0.wp.com/theexcelclub.com/wp-content/uploads/2017/05/1.0.png?resize=100%2C106 100w, https://i0.wp.com/theexcelclub.com/wp-content/uploads/2017/05/1.0.png?resize=275%2C291 275w" alt="DAX for powerpivot course" width="434" height="460"><br/> </a><figcaption>BEST SELLING COURSE</figcaption></figure>
The role of both DAX SUM and SUMX functions is to add numerical data together. Yet both these functions are rather different.

Let's talk about the SUM function first. The SUM function is simple. It takes a column of data and adds the values to give a total. It works like the sum function in Excel but Excel works on cell references or cell ranges and DAX works in columns.

But if you want to filter the data which you are adding, then you need to use the SUMX function. The Syntax is

SUMX(Table, Expression)

Where

Table: is the table containing the rows for which we will carry out the calculation.

Expression: is the calculation that will be evaluated on each row of the table.

Comparing DAX SUMX to Excel, you could say it works a bit like SUMProduct and complex Array formula.
<h4>What we will look at today</h4>
In this article and video, we are going to look at both SUM and SUMX in DAX. You will learn what is the difference between SUM and SUMX and you will learn when and how you can use both of these DAX function.&nbsp; We will use Power Pivot in our example, but this works the same in Microsoft Power BI.

You might already know these functions, but not understand how they work. To master DAX for PowerPivot or PowerBI you need to know how it operates.&nbsp; So, have a look at the article and video anyway, as we are going to get under the hood of DAX SUM and SUMX functions.

<iframe src="https://www.youtube.com/embed/Gl6iwrqeJy4" width="560" height="315" frameborder="0" allowfullscreen="allowfullscreen"></iframe>
<h5><center><strong>Sign up for my newsletter – Don’t worry, I wont spam – Just useful Excel and Power BI tips and tricks to your inbox </strong></center></h5>
<a role="button" href="https://theexcelclub.newzenler.com/f/email-signup">
SIGN UP NOW
</a>
<h3>DAX SUM and SUMX functions</h3>
As with all DAX functions, SUM and SUMX within PowerPivot for Excel, Power BI and in Analysis Services. In this example, we will use Excel's Power Pivot.

First, we have a sales table. This table contains the following columns:

date, invoice number, customer ID, product ID, quantity and sales.

<img src="https://theexcelclub.com/wp-content/uploads/2017/02/sum1-1024x576.png" alt="SUM and SUMX in Power Pivot" width="1024" height="576"><br/>

We also have a Product table.&nbsp; The columns in this table are: product ID, category, name, color, supplier ID, cost price and sales price.

<img src="https://theexcelclub.com/wp-content/uploads/2017/02/sum2-1024x576.png" alt="dax-sum-and-sumx-functions" width="1024" height="576"><br/>

The aim is to calculate the total of the sales (or the sum of the sales). And, we will do this in several different ways. First, we’re going to look at the normal SUM function.&nbsp; Then we’re going to look the SUMX function. Finally, we will look at the differences between the two functions and when you should use each one of them.
<h3>SUM in DAX</h3>
First, you will notice we have a sales column in the sales table.&nbsp; To get a total of these sales we can add in a measure.

In Excel 2013 Power Pivot, you can add a measure from the calculation pane of the screen. If this calculations pane is not visible, from the Home ribbon,&nbsp; you can show(or hide) the calculations pane.

<img src="https://theexcelclub.com/wp-content/uploads/2017/02/sum3-1024x576.png" alt="DAX for Power BI and Power Pivot – SUM and SUMX Functions" width="1024" height="576"><br/>

Let’s go ahead and calculate our total for the sales column. By selecting any cell in the calculation area, we can enter our measure. By entering =SUM, you will see in the formula bar, the functions available, like in Excel.

<img src="https://theexcelclub.com/wp-content/uploads/2017/02/sum4-1024x576.png" alt="DAX sum across tables" width="1024" height="576"><br/>

The syntax for SUM is

=SUM([column])

The SUM function looks for a column name. As we enter the table name, which we know to be ‘Sales’, we will see a list of available columns, measures, and functions. The icons beside the names in the dropdown show what they are. An item with the “T” icon indicates a table.

<img src="https://theexcelclub.com/wp-content/uploads/2017/02/sum5-1024x576.png" alt="SUM and SUMX in DAX" width="1024" height="576"><br/>

As we want to take our sales column in our sales table, we would select Sales[Sales].&nbsp; we can then close our formula with a bracket.

<img src="https://theexcelclub.com/wp-content/uploads/2017/02/sum7-1024x576.png" alt="SUM and SUMX in dax" width="1024" height="576"><br/>

What we’ve done is we have taken a column from a table and we added the values of this column together.
<h4>But wait!</h4>
What if we didn’t have the sales value in this table? What if we only have the quantity and we wanted to get the total sales?

We do have, in our product table, a sales price. As a relationship joins these tables, we can carry out cross table calculations.&nbsp; From the sales table, we can take the quantity and multiply this by the sales price in the products tables.
<h3>RELATED</h3>
First, we will do this as a calculated column rather than a measure. To multiply a column against a column from a different, but a related table, we need to use <a href="https://theexcelclub.com/dax-power-pivot-power-bi-ssas-related-and-relatedtable/">the RELATED function</a>. The full expression we need to use is

=[qty] * RELATED(Products[Sales Price]

As with all DAX expressions, we start with equals. We will first select our quantity column as we wish to use this column to calculate the sales value.&nbsp; To do this we need to multiply the values in each row, by the corresponding sales price value in the products table.

To multiply this column, as it is not in the sale table, we need to use the RELATED function.&nbsp; The related function will allow us to reach into a different table and use a related value.

As the calculated column is in the sales table, we need to reach into the related products table to get the sales price.
<h4>Reading the Expression</h4>
=[qty] * RELATED(Products[Sales Price]

What this expression says is:

In the first row, take the quantity.&nbsp; Then, go over to the table products.&nbsp; Find the related sales price for the particular product and multiply it by the quantity.

DAX will then move down the sales table, row by row and carry out this calculation.

By right-clicking on the column we can rename this column ‘Cal sales’. If we want to get our total sales we now need to SUM our new calculated column. In the measures area enter the following expression

=SUM(Sales(cal sales))

This measure will now add all the values from our calculated column.

<img src="https://theexcelclub.com/wp-content/uploads/2017/02/sum8-1024x576.png" alt="Related and sum in DAX" width="1024" height="576"><br/>
<h4>Wrapping up SUMX</h4>
To note. Calculated columns, when added as a value to a pivot table or chart, will create an implicit measure. This is because the values from columns are aggregated when added to pivot tables and visualizations.

And that’s how we would reach into another table to carry out the calculation and finally get a total Sales value.

But this way is quite long and is very heavy on your computer’s resources.&nbsp; You see DAX stores calculations carried out in a calculated column in the model. Whereas measures are only calculated when they’re needed.
<h3>Introducing Row Level calculations in DAX</h3>
DAX carries out calculated columns at the row level, one row at a time. In this example, what DAX does is it goes to the first row and in the first row goes to the quantity and takes that value. Then it hops over to the products table and looks for the sales price for the corresponding product. These values are multiplied against each other. Then DAX goes down to the next row and does the same thing for that row, and so on. This is at row level and this is an important concept of DAX to understand. We always carry out calculated columns at row level.
<h3>SUMX IN DAX</h3>
What we’re going to look at now is another solution to calculate sales.

Let’s assume we didn’t have the sales column in our sales table and we didn’t want a new calculated column. All we want is one measure. Well, what we can do now is use the SUMX function.

The SUMX function will allow you to sum things across different tables. It would remind me of SUMPRODUCT in Excel. Let me show you what I mean.

We will create a new measure, and the measure is going to use SUMX.

The full measure is

=SUMX(Sales, Sales[Qty]* RELATED(Products[sales price]))

SUMX&nbsp; ‘returns the SUM of an expression evaluated for each row in a table’. It’s a table function and the first thing it looks for is the table.

So, what table is it that this calculation is going to take place in?

<img src="https://theexcelclub.com/wp-content/uploads/2017/02/sum10-1024x576.png" alt="" width="1024" height="576"><br/>

Well, the table is going to be our sales table.

Next, DAX says 'what expression do you want to SUM the values from in the sales table?'

An expression is a formula.&nbsp; Our formula is going to be our quantity * sales price.&nbsp;&nbsp; But we need to wrap RELATED to our sales price, as it is from a different table.
<h4>Reading the Expression</h4>
Reading this formula in English. The formula is saying

'go to the sales table and get the quantity then, multiply the sales quantity by the related product price.'

DAX will go row by row, down the sales table. It will take the sales quantity and multiply it by the related price in the products table. DAX will store the value for each row in its memory.&nbsp; When it gets to the end of the table, DAX will go to the outer formula, SUMX, and will sum all these stored values together.

Calculating total sales using the SUMX function gives us the same result as each of the previous examples.&nbsp; It is important to learn that you don't always need to create a calculated column.
<h3>Iterator's</h3>
We can slice and we can dice this measure that we create. You see the SUMX function is an iterator.&nbsp; Iterators are something you will come across often in DAX. An Iterator defines the ROW context for a DAX formula.&nbsp; So that means it tells DAX on which rows to carry out a calculation and the filter context used with slicers does not break this. Row context and filter context are different. And they both must be taken into consideration when you’re creating DAX measures.
<figure><a href="https://theexcelclub.newzenler.com/courses/master-dax-fundamentals-power-bi-amp-power-pivot" data-elementor-open-lightbox="">
<img src="https://theexcelclub.com/wp-content/uploads/2017/05/1.0.png" sizes="(max-width: 434px) 100vw, 434px" srcset="https://i0.wp.com/theexcelclub.com/wp-content/uploads/2017/05/1.0.png?w=434 434w, https://i0.wp.com/theexcelclub.com/wp-content/uploads/2017/05/1.0.png?resize=283%2C300 283w, https://i0.wp.com/theexcelclub.com/wp-content/uploads/2017/05/1.0.png?resize=410%2C435 410w, https://i0.wp.com/theexcelclub.com/wp-content/uploads/2017/05/1.0.png?resize=100%2C106 100w, https://i0.wp.com/theexcelclub.com/wp-content/uploads/2017/05/1.0.png?resize=275%2C291 275w" alt="DAX for powerpivot course" width="434" height="460"><br/> </a>

<figcaption>BEST SELLING COURSE</figcaption></figure>
<h2>Learn and Earn Activity</h2>
<b>To earn steem rewards on this post, in the comments section below answer the following questions:</b>

<b>Before you read this article and watch the video, how would you rate your understanding of&nbsp; SUM and SUMX functions in DAX?&nbsp; Poor, Ok or Great?</b>

<b>How would you rate your understanding now that you have completed the article?</b>

<b>What are your key takeaways from this post?</b>
<h4><center><strong>In return for this article -DAX SUM and SUMX Functions- I ask that you share this post or the video with your friends and colleagues</strong></center></h4>
<h4><strong>Sign up for my newsletter – Don’t worry, I wont spam – Just useful Excel and Power BI tips and tricks to your inbox</strong></h4>
<a role="button" href="https://theexcelclub.newzenler.com/f/email-signup">
SIGN UP
</a>
<img src="https://theexcelclub.com/wp-content/uploads/2019/05/steem-1.png" sizes="(max-width: 225px) 100vw, 225px" srcset="https://i2.wp.com/theexcelclub.com/wp-content/uploads/2019/05/steem-1.png?w=225 225w, https://i2.wp.com/theexcelclub.com/wp-content/uploads/2019/05/steem-1.png?resize=150%2C150 150w, https://i2.wp.com/theexcelclub.com/wp-content/uploads/2019/05/steem-1.png?resize=100%2C100 100w" alt="learn and earn excel activities" width="225" height="225"><br/>
<h3><center><strong>Now there is value in Learning with The Excel Club and our Learn and Earn STEEM activities.</strong></center></h3>
<p><center><strong>We are the first Excel, PowerBI and DAX blog in the world where you can Earn while you Learn.</strong></center></p>

<center><a href="https://theexcelclub.com/learn-and-earn-steem-activities/">Find out more now and start earning while you are learning Excel and Power BI</a></center></h3> <br /><center><hr/><em>Cross posted from my blog with <a href='https://wordpress.org/plugins/steempress/'>SteemPress</a> : http://theexcelclub.com/dax-sum-and-sumx-functions/ </em><hr/></center>          
👍  , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , and 6 others
👎  ,
properties (23)
authortheexcelclub
permlinkdaxsumandsumxfunctions-1hmhv2xeyx
categoryexcel
json_metadata{"community":"steempress","app":"steempress","image":["http://theexcelclub.com/wp-content/uploads/2017/02/sumx.png"],"tags":["excel","stem","palnet","steemleo","tutorials"],"canonical_url":"http://theexcelclub.com/dax-sum-and-sumx-functions/"}
created2019-08-16 13:01:42
last_update2019-10-25 21:42:51
depth0
children6
last_payout2019-08-23 13:01:42
cashout_time1969-12-31 23:59:59
total_payout_value44.223 HBD
curator_payout_value17.053 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length14,159
author_reputation49,417,421,433,400
root_title"DAX SUM and SUMX Functions"
beneficiaries
0.
accountsteempress
weight1,500
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id89,596,214
net_rshares204,544,095,144,184
author_curate_reward""
vote details (72)
@abh12345.stem · (edited)
$0.22
Good stuff Paula :)

Commentators on this post will get STEM votes from me!
👍  
properties (23)
authorabh12345.stem
permlinkpwdmea
categoryexcel
json_metadata{"tags":["excel","stem"],"app":"stemgeeks/0.1"}
created2019-08-17 10:27:45
last_update2019-08-17 10:29:00
depth1
children1
last_payout2019-08-24 10:27:45
cashout_time1969-12-31 23:59:59
total_payout_value0.166 HBD
curator_payout_value0.055 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length75
author_reputation410,560,470,359
root_title"DAX SUM and SUMX Functions"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id89,627,519
net_rshares654,404,890,863
author_curate_reward""
vote details (1)
@paulag ·
Thanks @abh12345.stem, nice of you to drop by.  You should try this, learning power pivot means the transition to powerbi is just learning the interface :-)
properties (22)
authorpaulag
permlinkpwe2wf
categoryexcel
json_metadata{"tags":["excel"],"users":["abh12345.stem"],"app":"steemit/0.1"}
created2019-08-17 16:24:18
last_update2019-08-17 16:24:18
depth2
children0
last_payout2019-08-24 16:24:18
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length156
author_reputation274,264,287,951,003
root_title"DAX SUM and SUMX Functions"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id89,637,149
net_rshares0
@deebawriter ·
Bitcoin and blockchain news read at https://btcmanager.com/
Join telegram https://t.me/btcmanagernews
properties (22)
authordeebawriter
permlinkpwfpzg
categoryexcel
json_metadata{"tags":["excel"],"links":["https://btcmanager.com/","https://t.me/btcmanagernews"],"app":"steemit/0.1"}
created2019-08-18 13:40:30
last_update2019-08-18 13:40:30
depth1
children0
last_payout2019-08-25 13:40:30
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length101
author_reputation-799,382,227,541
root_title"DAX SUM and SUMX Functions"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id89,665,390
net_rshares0
@terrybaugh ·
$0.27
2zmwq81rc4
Before the post, ok.  After the post, great.  Primary takeaway is the difference in aggregators and iterators.
👍  ,
properties (23)
authorterrybaugh
permlinksg9rwk8vobpsaj1
categoryexcel
json_metadata{"app":"steempress/2.0"}
created2020-09-13 02:10:33
last_update2020-09-13 02:10:33
depth1
children1
last_payout2020-09-20 02:10:33
cashout_time1969-12-31 23:59:59
total_payout_value0.134 HBD
curator_payout_value0.135 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length110
author_reputation66,616,991,972
root_title"DAX SUM and SUMX Functions"
beneficiaries
0.
accountsteempress
weight100
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id99,597,518
net_rshares1,423,161,542,327
author_curate_reward""
vote details (2)
@paulag ·
Yeah aggregators and iterators have different roles in Dax and its an important concept to understand
properties (22)
authorpaulag
permlinkre-terrybaugh-qgm8di
categoryexcel
json_metadata{"tags":["excel"],"app":"peakd/2020.09.4"}
created2020-09-13 21:15:18
last_update2020-09-13 21:15:18
depth2
children0
last_payout2020-09-20 21:15:21
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length101
author_reputation274,264,287,951,003
root_title"DAX SUM and SUMX Functions"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id99,610,578
net_rshares0
@tts ·
To listen to the audio version of this article click on the play image.
[![](https://s18.postimg.org/51o0kpijd/play200x46.png)](http://ec2-52-72-169-104.compute-1.amazonaws.com/theexcelclub__daxsumandsumxfunctions-1hmhv2xeyx.mp3)
Brought to you by [@tts](https://steemit.com/tts/@tts/introduction). If you find it useful please consider upvoting this reply.
properties (22)
authortts
permlinkre-daxsumandsumxfunctions-1hmhv2xeyx-20190816t134130
categoryexcel
json_metadata""
created2019-08-16 13:41:30
last_update2019-08-16 13:41:30
depth1
children0
last_payout2019-08-23 13:41:30
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length357
author_reputation-4,535,154,553,995
root_title"DAX SUM and SUMX Functions"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id89,597,422
net_rshares0