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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
user01
Resolver I
Resolver I

Measure that calculates subtotal in matrix and also works in pie chart

I have two tables Reference and Table. I bring them in by DirectQuery. I have a measure that does some calculations. I've simplified the tables and measures for convenience/illustration. When I put FinalMeasure in a matrix, it calculates everything correctly at the SubCategory level. 

 

Goals:

1. I want to display the subtotals at the Category level as well.

2. I want to be able to put this measure in a pie chart to look at the pie at either the SubCategory level or the Category level.

 

How can I accomplish this?

 

FactorMeasure = 1 

 

 

 

FinalMeasure = 
var _subcat = SELECTEDVALUE('Table'[SubCategory])
var _var = SELECTEDVALUE('Table'[Variable])
var _factor = [FactorMeasure]
var _amt = LOOKUPVALUE(Reference[Amount], Reference[Variable], _var)
var _amtc3 = LOOKUPVALUE(Reference[Amount], Reference[Variable], "_C3_")
var _calc = SWITCH(_subcat,
    "A1", _amt + 1,
    "A2", _amt + 2,
    "B", _amt + 3,
    "C1", _amt + 4,
    "C2", _amt + 5,
    BLANK()
)*_factor
return SUMX('Table', IF(_subcat = "C3", _amtc3, _calc))

 

 

Current Results:

 

user01_2-1716938399458.png

 

 Desired Results (Excel example):

 

user01_1-1716937948650.png

 

Table:

CategorySubCategoryVariableKey
AA1_A1_1
AA2_A2_2
BB_B_3
CC1_C1_4
CC2_C2_5
CC3_C3_6

 

Reference:

VariableAmount
_A1_30200
_A2_5500
_B_17700
_C1_3600
_C2_18100
_C3_800
1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi, @user01 

Since both tables have a relationship, we just need to create a measure that uses the sum function.

 

vyohuamsft_0-1716948476429.png

FinalMeasure 2 = SUM('Reference'[Amount])

Here is my preview

vyohuamsft_1-1716948627024.png

 

How to Get Your Question Answered Quickly 

Best Regards

Yongkang Hua

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

1 REPLY 1
Anonymous
Not applicable

Hi, @user01 

Since both tables have a relationship, we just need to create a measure that uses the sum function.

 

vyohuamsft_0-1716948476429.png

FinalMeasure 2 = SUM('Reference'[Amount])

Here is my preview

vyohuamsft_1-1716948627024.png

 

How to Get Your Question Answered Quickly 

Best Regards

Yongkang Hua

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Helpful resources

Announcements
November Power BI Update Carousel

Power BI Monthly Update - November 2025

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

Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.

Top Solution Authors
Top Kudoed Authors