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

Join us for an expert-led overview of the tools and concepts you'll need to become a Certified Power BI Data Analyst and pass exam PL-300. Register now.

Reply
Syndicate_Admin
Administrator
Administrator

Problems calculating percentage over subtotal by option.

Good morning

Given the following example table:

Date Town Town Km_Asfaltados

1-2-2022 Madrid Getafe 10

3-2-2022 Seville Two Sisters 5

4-7-2022 Madrid Las Rozas 7

4-7-2022 Madrid Getafe 5

4-7-2022 Madrid Alcorcón 3

How can I calculate using DAX, the percentage of each town in asphalted km with respect to the total of km belonging to the same city of its corresponding day and show it in a new column?, I have tried to generate a summary table with "SUMARIZE" obtaining the subtotals by city, then creating a relationship between both tables by the city field to later use the function "DIVIDE" between the total of asphalted kg of each table to obtain the percentage, but I can not perform the formula well, plus I have the feeling that I am killing flies with cannon shots because I think it should be possible to do without generating a new summary table.

Please if you are so kind to throw me a cable to illuminate me, thank you very much!!

Greetings,

Jose.

1 ACCEPTED SOLUTION
Syndicate_Admin
Administrator
Administrator

Well indeed, it was complicating my life greatly. (It's what it takes to be a newbie at this xD)

As I have already solved it, I detail here the solution in case someone in the future could serve for a similar problem.

1.- I create a new measure that will house the totalization of the field Km_Asfaltados

ZMED_TotalKgAsfaltados = sum(Carreteras[Km_Asfaltados])

2.- I create a new calculated column that will obtain the total for each town.

ZCOL_Total_por_Pueblo           = 
 CALCULATE(SUM(Carreteras[Km_Asfaltados]),ALLEXCEPT(Carreteras,Carreteras[Pueblo],Carreteras[Fecha]))

3.- I calculate the percentage that represents the asphalted km of that town with respect to the total of its province.

ZMED_%_S/Pueblo = 
DIVIDE([ZMED_TotalKmAsfaltados], [ZCOL_Total_por_Pueblo])

Thanks a lot

Greetings!!.

View solution in original post

1 REPLY 1
Syndicate_Admin
Administrator
Administrator

Well indeed, it was complicating my life greatly. (It's what it takes to be a newbie at this xD)

As I have already solved it, I detail here the solution in case someone in the future could serve for a similar problem.

1.- I create a new measure that will house the totalization of the field Km_Asfaltados

ZMED_TotalKgAsfaltados = sum(Carreteras[Km_Asfaltados])

2.- I create a new calculated column that will obtain the total for each town.

ZCOL_Total_por_Pueblo           = 
 CALCULATE(SUM(Carreteras[Km_Asfaltados]),ALLEXCEPT(Carreteras,Carreteras[Pueblo],Carreteras[Fecha]))

3.- I calculate the percentage that represents the asphalted km of that town with respect to the total of its province.

ZMED_%_S/Pueblo = 
DIVIDE([ZMED_TotalKmAsfaltados], [ZCOL_Total_por_Pueblo])

Thanks a lot

Greetings!!.

Helpful resources

Announcements
Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

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

June 2025 community update carousel

Fabric Community Update - June 2025

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