SUMX + DISTINCT function

jroz2001

New Member
Joined
Feb 22, 2016
Messages
7
Goodday,

I want to use the SUMX function in combination with DISTINCT (PowerPivot + Excel 2010).

For example I have this data:
ProductgroupProductSales
Group Yproduct15
Group Yproduct24
Group Xproduct15
Group Xproduct33

<tbody>
</tbody>

Products can be assigned to multiple Productgroups. So product1 is in both, Group Y and Group X. If I create a PivotTable with PowerPivot, the total Sales of Group Y is 9, and total Sales of Group X is 8. However, overall total Sales is 17, while I want it to be 12 (so count product1 only once).
I found out that I should SUMX in combination with DISTINCT, so I created this one:
Code:
=SUMX(DISTINCT('table'[Product]), [Sales])
A new column is created, however, the values, including totals are equal with the ones in de Sales-column. I hope someone can help me with this!

Thanks in advance!
 

Excel Facts

How to create a cell-sized chart?
Tiny charts, called Sparklines, were added to Excel 2010. Look for Sparklines on the Insert tab.
Wow, interesting problem. Sumx as you have described won't work. The challenge is to determine a set of rules that uniquely identifies each product so you know if you have to sum it or not. The problem I have is that it is not clear what these rules are. Is is it possible to have 2 more rows as follows

group y. Product 1. 4
group X. Product 1. 4

And what about these

group y. Product 1. 3
group X. Product 1. 4

Do you have any other unique identifying Information or anything else you can share
 
Upvote 0
Hi jroz and Matt,

It sounds like you have a many-to-many relationship between Product and Productgroup, so a many-to-many model with separate Product & Productgroup tables & a bridging table should work here.

See this paper page 98 for an example of the model setup:
http://www.sqlbi.com/wp-content/uploads/The_Many-to-Many_Revolution_2.0.pdf
Comparing your model with the one in the paper:
  • Dim_Account would become Product
  • Dim_Customer would become Productgroup
  • Bridge_AccountCustomer would become Bridge_ProductgroupProduct

Your Sales table would just contain sales by Product, without needing to restate each sale for every group that product is in. (The bridge table captures that instead.)

See page 103 for an example of the actual many-to-many measure.
The SUMMARIZE(...) bit can be changed to just the name of the bridge table.

Here's an attempt in Excel 2010 with your sample tables:
https://www.dropbox.com/s/bo9q2uozy3m7rh6/Product Productgroup Many-to-many (excel 2010).xlsx?dl=0
 
Last edited:
Upvote 0
Ok, I figured it out! i don't know exactly how the formula works, but it works ;)
First I create a New Measure with, in this example the name 'maxsales'
Code:
=MAXX(DISTINCT('table'[Product]),MAX('table'[Sales]))
Then I create another new measure:
Code:
=SUMX(DISTINCT('table'[Product]),[maxsales])

Thanks anyway for trying to help me out!
 
Upvote 0

Forum statistics

Threads
1,214,979
Messages
6,122,552
Members
449,088
Latest member
davidcom

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top