Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Compete to become Power BI Data Viz World Champion! First round ends August 18th. Get started.

Reply
AndyBlasiak
New Member

Calculating a % of a "subtotal"

Hi Power BI Community,

 

Could you advise me on the DAX function or the full syntax to use to calculate % share for a "subtotal?

 

In the below table I want to calculate for each respective country a % share of product sold in respective country total sales (as shown in the last column).

CountryProductSales (tonnes)Product Structure per Country
USAPaper1213%
USASteel3537%
USAWood4750%
UKWood2239%
UKSteel3561%
PolandPaper4549%
PolandSteel1213%
PolandWood3437%

 

Looking forward to hearing from you.

 

Regards

 

Andrzej

1 ACCEPTED SOLUTION
Nathaniel_C
Community Champion
Community Champion

Hi @AndyBlasiak ,
Please try this:

Measure = 

var _product = MAX('Totals'[Product])
var _sales = MAX('Totals'[Sales (tonnes)])
var _country = max('Totals'[Country])
var _totalSales = SUM('Totals'[Sales (tonnes)])


var _totalCountrySales = CALCULATE(SUM('Totals'[Sales (tonnes)]), Filter(All('Totals'),'Totals'[Country]=_country))
var _divide = divide(_sales,_totalCountrySales)

return _divide


Let me know if you have any questions.

If this solves your issues, please mark it as the solution, so that others can find it easily. Kudos 👍are nice too.
Nathaniel





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




View solution in original post

2 REPLIES 2
Nathaniel_C
Community Champion
Community Champion

Hi @AndyBlasiak ,
Please try this:

Measure = 

var _product = MAX('Totals'[Product])
var _sales = MAX('Totals'[Sales (tonnes)])
var _country = max('Totals'[Country])
var _totalSales = SUM('Totals'[Sales (tonnes)])


var _totalCountrySales = CALCULATE(SUM('Totals'[Sales (tonnes)]), Filter(All('Totals'),'Totals'[Country]=_country))
var _divide = divide(_sales,_totalCountrySales)

return _divide


Let me know if you have any questions.

If this solves your issues, please mark it as the solution, so that others can find it easily. Kudos 👍are nice too.
Nathaniel





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




Hi @AndyBlasiak 
Bonus measure - if you want to calculate the % of a product that each country  produces with just a small change in the measure try this:

% of Product Sales per Country = 

var _product = MAX('Totals'[Product])
var _sales = MAX('Totals'[Sales (tonnes)])
var _country = MAX('Totals'[Country])

var _totalSales = SUM('Totals'[Sales (tonnes)])


var _totProductSales = CALCULATE(SUM('Totals'[Sales (tonnes)]), Filter(All('Totals'),'Totals'[Product]=_product))
var _divide = divide(_sales, _totProductSales)

return _divide



Let me know if you have any questions.

If this solves your issues, please mark it as the solution, so that others can find it easily. Kudos 👍are nice too.
Nathaniel


Nathaniel_C_0-1653923474213.png

 

 





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




Helpful resources

Announcements
August Power BI Update Carousel

Power BI Monthly Update - August 2025

Check out the August 2025 Power BI update to learn about new features.

August 2025 community update carousel

Fabric Community Update - August 2025

Find out what's new and trending in the Fabric community.