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

The Power BI DataViz World Championships are on! With four chances to enter, you could win a spot in the LIVE Grand Finale in Las Vegas. Show off your skills.

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
v-shex-msft
Community Support
Community Support

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

Community Support Team _ Xiaoxin
If this post helps, please consider accept as solution to help other members find it more quickly.
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



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

Community Support Team _ Xiaoxin
If this post helps, please consider accept as solution to help other members find it more quickly.

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

FebPBI_Carousel

Power BI Monthly Update - February 2025

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

Feb2025 NL Carousel

Fabric Community Update - February 2025

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