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

Get Fabric Certified for FREE during Fabric Data Days. Don't miss your chance! Learn more

Reply
Anonymous
Not applicable

Calculate MAX for subtotals

Hi,

 

Need assistance in calculating MAX as subtotals in a Matrix. 

In the below sample data set, I am trying to arrive at Subtotals for Packages (highlighted in red font) where subtotal for each package should be MAX across ALL packages of that Distributor.

 

Item 1    
 Distributor A   18
  Package 1 18
   State 11
   State 22
   State 33
  Package 2 18
   State 12
   State 23
   State 34
  Package 3 18
   State 13
   State 24
   State 35
   State 46

PS - The data set contains multiple items, distributors and packages.

 

Thanks in advance!

1 ACCEPTED SOLUTION

Hi, @Anonymous 

 

You may modify the measure like below. The pbix file is attached in the end.

Result Measure = 
IF(
    ISINSCOPE('Table'[State]),
    SUM('Table'[Value]),
    IF(
        ISINSCOPE('Table'[Package]),
        MAXX(
                SUMMARIZE(
                    FILTER(
                        ALL('Table'),
                        [Item]=MAX('Table'[Item])&&
                        [Distributor]=MAX('Table'[Distributor])
                    ),
                    'Table'[Item],
                    'Table'[Distributor],
                    'Table'[Package],
                    "Result",
                    SUM('Table'[Value])
                ),
                [Result]
            ),
        MAXX(
                SUMMARIZE(
                    'Table',
                    'Table'[Item],
                    'Table'[Distributor],
                    'Table'[Package],
                    "Result",
                    SUM('Table'[Value])
                ),
                [Result]
        )
    )
)

 

Result:

c1.png

 

Best Regards

Allan

 

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

7 REPLIES 7
v-alq-msft
Community Support
Community Support

Hi, @Anonymous 

 

The link provided is unavailable. I created data to reproduce your scenario. The pbix file is attached in the end.

Table:

a1.png

 

You may create a measure like below.

Result Measure = 
IF(
    ISINSCOPE('Table'[State]),
    SUM('Table'[Value]),
    IF(
        ISINSCOPE('Table'[Package]),
        SUM('Table'[Value]),
        IF(
            ISINSCOPE('Table'[Distributor]),
            MAXX(
                SUMMARIZE(
                    'Table',
                    'Table'[Item],
                    'Table'[Distributor],
                    'Table'[Package],
                    "Result",
                    SUM('Table'[Value])
                ),
                [Result]
            ),
            SUM('Table'[Value])
        )
    )
)

 

Result:

b1.png

 

Best Regards

Allan

 

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

Anonymous
Not applicable

Hi Allan @v-alq-msft ,

Sorry for the inconvenience, the link must've expired. New link - https://we.tl/t-LFy0jJ9yig

Thank you for the above measure. It partly solves the problem in hand. However the package and item subtotal still does not match the desired output!
I want the package subtotal to be MAX of all packages for that particular Distribtor. In other words, continuing to the above example, subtotal for Package 1, Package 2 and Package 3 should also be 36 when we have not drilled down upto State level information. And similarly subtotal for Package 4, Package 5 and Package 6 should be 48.
Additionally subtotal for Item 1 should be Max of Distributors which is 36 and likewise subtotal for Item 2 should be 48.
Would that be possible?
Thanks!

Hi, @Anonymous 

 

You may modify the measure like below. The pbix file is attached in the end.

Result Measure = 
IF(
    ISINSCOPE('Table'[State]),
    SUM('Table'[Value]),
    IF(
        ISINSCOPE('Table'[Package]),
        MAXX(
                SUMMARIZE(
                    FILTER(
                        ALL('Table'),
                        [Item]=MAX('Table'[Item])&&
                        [Distributor]=MAX('Table'[Distributor])
                    ),
                    'Table'[Item],
                    'Table'[Distributor],
                    'Table'[Package],
                    "Result",
                    SUM('Table'[Value])
                ),
                [Result]
            ),
        MAXX(
                SUMMARIZE(
                    'Table',
                    'Table'[Item],
                    'Table'[Distributor],
                    'Table'[Package],
                    "Result",
                    SUM('Table'[Value])
                ),
                [Result]
        )
    )
)

 

Result:

c1.png

 

Best Regards

Allan

 

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

Anonymous
Not applicable

Thank you so much Allan! 😎

Anonymous
Not applicable

https://we.tl/t-nGlBPRhNoN 

Link to download sample data in excel capturing the logic required behind subtotals and grandtotal with the desired output.  

amitchandak
Super User
Super User

@Anonymous , While I need more data for excat formula, You can use isinscope to get that

 

example

If(isinscope(Table[Distributor]), maxx(all(Table[Distributor]), [Value]),[Value])

 

refer this - https://www.kasperonbi.com/use-isinscope-to-get-the-right-hierarchy-level-in-dax/

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube
Anonymous
Not applicable

Hi @amitchandak,

 

Thanks for the suggestion! The if isinscope function gives me the following error - Too many arguments were passed to the ISINSCOPE function. The maximum argument count for the function is 1. Let me know if i'm missing something! 

Helpful resources

Announcements
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!

October Power BI Update Carousel

Power BI Monthly Update - October 2025

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

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