Correct way of getting % Of (Power BI Desktop) - Measure

MarkCBB

Active Member
Joined
Apr 12, 2010
Messages
497
Hello,

I am busy messing around with some data to improve my DAX. I am using a very simple table (2 Columns, Column 1 = Product, Column 2 = Sales). (Note, unique list of products)

I am trying to get the percent of each Product i.e. sales contribution. When I create a pie chart with the 2 columns I get the expected result, the values are based on the value of the sum of sales.

Now I am trying to get the values in the Pie chart to show the percentage. I came up with the below Dax measure, and it works, but I am sure that there is a better way of doing this.
Code:
% of = DIVIDE(CALCULATE(SUM(Sheet1[Sales]),FIRSTNONBLANK(Sheet1[Products],SUM(Sheet1[Sales]))),CALCULATE(SUM(Sheet1[Sales]),ALL(Sheet1[Products])),0)

Table%20of%20Data.bmp
 

Excel Facts

Can Excel fill bagel flavors?
You can teach Excel a new custom list. Type the list in cells, File, Options, Advanced, Edit Custom Lists, Import, OK
Try this

divide (sum(sheet1[sales]),calulate(sum(sheet1[sales]),all(sheet1)))

the he first half of divide returns the product total. The second half returns the table total.
 
Last edited:
Upvote 0
Thank you Matt, that is perfect. and works on other items besides Product.
Thank you once again for your on going assistance.
I am having so much fun learning DAX
 
Upvote 0

Forum statistics

Threads
1,224,163
Messages
6,176,789
Members
452,743
Latest member
Unique65

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