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

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.

Reply
Asmoday1507
Frequent Visitor

How to calculate subtotal correctly with hierarchies

Hi

I am struggling with the following problem. I have a fact table in which I already receive calculated values per category and subcategory in one table. The totals per category and subcategory do not and should not be equal.

Let's assume we have category A, which is divided into 3 subcategories: AA, AB, AC. The entire category A is supposed to have a subtotal of 370, and the subcategory AA is 50, AB 100 and AC 200. The sum of the subcategories is 350, but I would not like to see 350, but 370.

I already receive the calculated data from the backend layer:

Zrzut ekranu 2025-02-19 080723.png

Since I have one column with values that simultaneously contains the sum of the entire category and the subcategory values, the whole thing is duplicated in the sums. How can I approach this differently?

 

Zrzut ekranu 2025-02-19 080559.png

This is an example, the real case has a category and a tree with 8 levels of subcategories, so it is very important for me that the solution is calculated correctly.

5 REPLIES 5
Anonymous
Not applicable

Hi @Asmoday1507 ,

Did the above suggestions help with your scenario? if that is the case, you can consider Kudo or Accept the helpful suggestions to help others who faced similar requirements.

If these also don't help, please share more detailed information and description to help us clarify your scenario to test.

How to Get Your Question Answered Quickly 

Regards,

Xiaoxin Sheng

tamerj1
Super User
Super User

Hi @Asmoday1507 

your table is already structured as a matrix. Just put it in a table visual and will display as a matrix. 

ValtteriN
Super User
Super User

Hi,

You can use ISINSCOPE to change the calculation logic depeding on the level of the visualization. E.g.

Measure 32 = SWITCH(TRUE(),ISINSCOPE('Table (48)'[Subcategory]),
SUM('Table (48)'[Value]),
CALCULATE(
SUM('Table (48)'[Value]),'Table (48)'[Subcategory] in {"A"}))

ValtteriN_0-1739950248949.png

 

This will give the sum of subcategory A in total level an in the subcategory level the values are shown as normal.

I hope this post helps to solve your issue and if it does consider accepting it as a solution and giving the post a thumbs up!

My LinkedIn: https://www.linkedin.com/in/n%C3%A4ttiahov-00001/




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

Proud to be a Super User!




Yes, Isinscope dax function is useful, but I don't want to see value from A in my table, value for A is only calculated subtotal in backend. 

Asmoday1507_0-1739950488706.png

Also it's only an example, real scenario has a tree with 8 subcategories, 8 subsubcategories etc



Anonymous
Not applicable

HI @Asmoday1507,

Did you mean to calculate with category fields but not really use this in the visual axis?
If that is the case, you may need to add variable in measure to restore the current category group and calculate correspond result.

All the secrets of SUMMARIZE - SQLBI
Then you can lookup above variable table and filter records based on current row contexts.

Regards,

Xiaoxin Sheng

Helpful resources

Announcements
July 2025 community update carousel

Fabric Community Update - July 2025

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

July PBI25 Carousel

Power BI Monthly Update - July 2025

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