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
Anonymous
Not applicable

Measure totals in matrix with hierarchy

Hi all,

 

I've got such a matrix.

Rows: Channel, Customer, Segment; Columns: Year-Period; Values: MyMeasure = IF(Table[Amount]<0;0;Table[Amount]).
Surely, PBI calculates totals not as I expect it. As you can see the sum of Segments doesn't equal Customer's subtotals.

 

 2019-P092019-P10
Channel-17075
 Customer-15045
  Segment-11010
  Segment-22010
  Segment-33030
  Segment-400
 Customer-22030
  Segment-11015
  Segment-200
  Segment-32020

 

I tried this measure: SUMX(FILTER(VALUES(Table[Segment]);Table[Amount]>0);Table[Amount])+0

Now I have correct subtotals at the level of Customer, but at the Channel level of hierarchy subtotals are still incorrect.

 

 2019-P092019-P10
Channel-17075
 Customer-16050
  Segment-11010
  Segment-22010
  Segment-33030
  Segment-400
 Customer-23035
  Segment-11015
  Segment-200
  Segment-32020

 

Please, help me to write the correct DAX for this matrix.

1 ACCEPTED SOLUTION
technolog
Super User
Super User

To address the issue with correct totals at different levels of the hierarchy in your matrix, you can use the SUMX function to iterate over the values properly at each level. The challenge is ensuring that the total at each level (Channel, Customer, Segment) respects the conditions you set for the measure.

Here is how you can adjust your measure:

MyMeasure = 
SUMX(
    VALUES(Table[Segment]),
    IF(Table[Amount] < 0, 0, Table[Amount])
)

If this does not give the desired results, you can adjust it to handle each hierarchy level by checking the context. This is a more advanced solution using ISINSCOPE:

MyMeasure = 
IF(
    ISINSCOPE(Table[Segment]),
    IF(Table[Amount] < 0, 0, Table[Amount]),
    SUMX(
        VALUES(Table[Segment]),
        IF([Total Amount] < 0, 0, [Total Amount])
    )
)

View solution in original post

1 REPLY 1
technolog
Super User
Super User

To address the issue with correct totals at different levels of the hierarchy in your matrix, you can use the SUMX function to iterate over the values properly at each level. The challenge is ensuring that the total at each level (Channel, Customer, Segment) respects the conditions you set for the measure.

Here is how you can adjust your measure:

MyMeasure = 
SUMX(
    VALUES(Table[Segment]),
    IF(Table[Amount] < 0, 0, Table[Amount])
)

If this does not give the desired results, you can adjust it to handle each hierarchy level by checking the context. This is a more advanced solution using ISINSCOPE:

MyMeasure = 
IF(
    ISINSCOPE(Table[Segment]),
    IF(Table[Amount] < 0, 0, Table[Amount]),
    SUMX(
        VALUES(Table[Segment]),
        IF([Total Amount] < 0, 0, [Total Amount])
    )
)

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.

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.