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! Request now

Reply
tian
Frequent Visitor

SUM By GROUP by Slicer

Hi Guys, I have data like this:

CompanyCategorySub-CategoryProduct Namesales
ACOMPFOOD1A1000
ACOMPFOOD1B1500
ACOMPFOOD1C2000
ACOMPFOOD2D3000
ACOMPRETAIL2E2000
ACOMPRETAIL2F1000
BCOMPRETAIL3G1000
BCOMPRETAIL3H5000
BCOMPSERVICE4I2500
BCOMPSERVICE4J1000


The case when I put the slicer based on Product name, the value also keep SUM of Product Name.

My Expectation result, when I put the slicer based on Product Name can show SUM of Group in a Card Visual, looks like:
Snag_28714774.png

Sorry for my explanation in Excel mode, that's to make it clear enough.

Does someone know how to this calculation in Dax

Thanks in advance for your help.


BR


1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi @tian 

I think you need to create an unrelated Product Name table. Then build a slicer by this table and create measures.

Product Name = VALUES('Table'[Product Name])

Measure codes:

% Sub-Category = 
VAR _SelectProductName =
    SELECTEDVALUE ( 'Product Name'[Product Name] )
VAR _SubCategory =
    CALCULATE (
        MAX ( 'Table'[Sub-Category] ),
        FILTER ( ALL ( 'Table' ), 'Table'[Product Name] = _SelectProductName )
    )
VAR _SalesbyGroup =
    CALCULATE (
        SUM ( 'Table'[sales] ),
        FILTER ( ALL ( 'Table' ), 'Table'[Sub-Category] = _SubCategory )
    )
VAR _Total =
    CALCULATE ( SUM ( 'Table'[sales] ), ALL ( 'Table' ) )
RETURN
    DIVIDE ( _SalesbyGroup, _Total )
% Category = 
VAR _SelectProductName =
    SELECTEDVALUE ( 'Product Name'[Product Name] )
VAR _Category =
    CALCULATE (
        MAX ( 'Table'[Category] ),
        FILTER ( ALL ( 'Table' ), 'Table'[Product Name] = _SelectProductName )
    )
VAR _SalesbyGroup =
    CALCULATE (
        SUM ( 'Table'[sales] ),
        FILTER ( ALL ( 'Table' ), 'Table'[Category] = _Category )
    )
VAR _Total =
    CALCULATE ( SUM ( 'Table'[sales] ), ALL ( 'Table' ) )
RETURN
    DIVIDE ( _SalesbyGroup, _Total )
% Company = 
VAR _SelectProductName =
    SELECTEDVALUE ( 'Product Name'[Product Name] )
VAR _Company =
    CALCULATE (
        MAX ( 'Table'[Company] ),
        FILTER ( ALL ( 'Table' ), 'Table'[Product Name] = _SelectProductName )
    )
VAR _SalesbyGroup =
    CALCULATE (
        SUM ( 'Table'[sales] ),
        FILTER ( ALL ( 'Table' ), 'Table'[Company] = _Company )
    )
VAR _Total =
    CALCULATE ( SUM ( 'Table'[sales] ), ALL ( 'Table' ) )
RETURN
    DIVIDE ( _SalesbyGroup, _Total )

Result is as below.

1.png

Best Regards,
Rico Zhou

 

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

2 REPLIES 2
Anonymous
Not applicable

Hi @tian 

I think you need to create an unrelated Product Name table. Then build a slicer by this table and create measures.

Product Name = VALUES('Table'[Product Name])

Measure codes:

% Sub-Category = 
VAR _SelectProductName =
    SELECTEDVALUE ( 'Product Name'[Product Name] )
VAR _SubCategory =
    CALCULATE (
        MAX ( 'Table'[Sub-Category] ),
        FILTER ( ALL ( 'Table' ), 'Table'[Product Name] = _SelectProductName )
    )
VAR _SalesbyGroup =
    CALCULATE (
        SUM ( 'Table'[sales] ),
        FILTER ( ALL ( 'Table' ), 'Table'[Sub-Category] = _SubCategory )
    )
VAR _Total =
    CALCULATE ( SUM ( 'Table'[sales] ), ALL ( 'Table' ) )
RETURN
    DIVIDE ( _SalesbyGroup, _Total )
% Category = 
VAR _SelectProductName =
    SELECTEDVALUE ( 'Product Name'[Product Name] )
VAR _Category =
    CALCULATE (
        MAX ( 'Table'[Category] ),
        FILTER ( ALL ( 'Table' ), 'Table'[Product Name] = _SelectProductName )
    )
VAR _SalesbyGroup =
    CALCULATE (
        SUM ( 'Table'[sales] ),
        FILTER ( ALL ( 'Table' ), 'Table'[Category] = _Category )
    )
VAR _Total =
    CALCULATE ( SUM ( 'Table'[sales] ), ALL ( 'Table' ) )
RETURN
    DIVIDE ( _SalesbyGroup, _Total )
% Company = 
VAR _SelectProductName =
    SELECTEDVALUE ( 'Product Name'[Product Name] )
VAR _Company =
    CALCULATE (
        MAX ( 'Table'[Company] ),
        FILTER ( ALL ( 'Table' ), 'Table'[Product Name] = _SelectProductName )
    )
VAR _SalesbyGroup =
    CALCULATE (
        SUM ( 'Table'[sales] ),
        FILTER ( ALL ( 'Table' ), 'Table'[Company] = _Company )
    )
VAR _Total =
    CALCULATE ( SUM ( 'Table'[sales] ), ALL ( 'Table' ) )
RETURN
    DIVIDE ( _SalesbyGroup, _Total )

Result is as below.

1.png

Best Regards,
Rico Zhou

 

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

amitchandak
Super User
Super User

@tian , based on what I got

 

measure = divide(sum(Table[Sales]), calculate(sum(Table[Sales]), all(Table)))

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

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