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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
AshDil
Helper V
Helper V

Want to show total sum by sub-category in one row only

Hi,

 

I have data as follows:

IDCATEGORYSUB-CATEGORYVALUE
1001AAA1000
1001AAA1200
1001BBB300
1001BBB2000
1002CCC100
1002CCC4000
1002DDD3500
1003FEE2000

 

Now I wanted to create a calculated column to show total sub-category sum in one row only

Eg: Under ID = 1001

category = A, B

There are 2 sub-categories AA and BB

Now want to show AA total AA sum = 1000 + 1200 = 2000 in one row 

IDCATEGORYSUB-CATEGORYVALUECOLUMN
1001AAA10002200
1001AAA1200 
1001BBB3002300
1001BBB2000 
1002CCC1004100
1002CCC4000 
1002DDD35003500
1003FEE20002000

Please help me to do it.

 

Thanks,

AshDil

1 ACCEPTED SOLUTION
danextian
Super User
Super User

Hi @AshDil ,

First add ann index column in Power Query. This will serve as a helper column to make only one row in the data show the total value.

danextian_0-1654058583831.png

Then in the Designer, add this as a calculated column

Column = 
VAR __MIN_INDEX =
    CALCULATE (
        MIN ( MyTable[Index] ),
        FILTER (
            MyTable,
            MyTable[CATEGORY] = EARLIER ( MyTable[CATEGORY] )
                && MyTable[SUB-CATEGORY] = EARLIER ( MyTable[SUB-CATEGORY] )
        )
    )
RETURN
    IF (
        __MIN_INDEX = MyTable[Index],
        CALCULATE (
            SUM ( MyTable[VALUE] ),
            FILTER (
                MyTable,
                MyTable[CATEGORY] = EARLIER ( MyTable[CATEGORY] )
                    && MyTable[SUB-CATEGORY] = EARLIER ( MyTable[SUB-CATEGORY] )
            )
        )
    )

danextian_1-1654058628479.png

Here's the sample PBIX for your reference: https://drive.google.com/file/d/18FiQn-bj8k6jCmZDMK2xmp6Q88ttYL6s/view?usp=sharing 










Did I answer your question? Mark my post as a solution!


Proud to be a Super User!









"Tell me and I’ll forget; show me and I may remember; involve me and I’ll understand."
Need Power BI consultation, get in touch with me on LinkedIn or hire me on UpWork.
Learn with me on YouTube @DAXJutsu or follow my page on Facebook @DAXJutsuPBI.

View solution in original post

3 REPLIES 3
danextian
Super User
Super User

Hi @AshDil ,

First add ann index column in Power Query. This will serve as a helper column to make only one row in the data show the total value.

danextian_0-1654058583831.png

Then in the Designer, add this as a calculated column

Column = 
VAR __MIN_INDEX =
    CALCULATE (
        MIN ( MyTable[Index] ),
        FILTER (
            MyTable,
            MyTable[CATEGORY] = EARLIER ( MyTable[CATEGORY] )
                && MyTable[SUB-CATEGORY] = EARLIER ( MyTable[SUB-CATEGORY] )
        )
    )
RETURN
    IF (
        __MIN_INDEX = MyTable[Index],
        CALCULATE (
            SUM ( MyTable[VALUE] ),
            FILTER (
                MyTable,
                MyTable[CATEGORY] = EARLIER ( MyTable[CATEGORY] )
                    && MyTable[SUB-CATEGORY] = EARLIER ( MyTable[SUB-CATEGORY] )
            )
        )
    )

danextian_1-1654058628479.png

Here's the sample PBIX for your reference: https://drive.google.com/file/d/18FiQn-bj8k6jCmZDMK2xmp6Q88ttYL6s/view?usp=sharing 










Did I answer your question? Mark my post as a solution!


Proud to be a Super User!









"Tell me and I’ll forget; show me and I may remember; involve me and I’ll understand."
Need Power BI consultation, get in touch with me on LinkedIn or hire me on UpWork.
Learn with me on YouTube @DAXJutsu or follow my page on Facebook @DAXJutsuPBI.
danextian
Super User
Super User

Hi @AshDil ,

First add ann index column in Power Query. This will serve as a helper column to make only one row in the data show the total value.

danextian_0-1654058583831.png

Then in the Designer, add this as a calculated column

Column = 
VAR __MIN_INDEX =
    CALCULATE (
        MIN ( MyTable[Index] ),
        FILTER (
            MyTable,
            MyTable[CATEGORY] = EARLIER ( MyTable[CATEGORY] )
                && MyTable[SUB-CATEGORY] = EARLIER ( MyTable[SUB-CATEGORY] )
        )
    )
RETURN
    IF (
        __MIN_INDEX = MyTable[Index],
        CALCULATE (
            SUM ( MyTable[VALUE] ),
            FILTER (
                MyTable,
                MyTable[CATEGORY] = EARLIER ( MyTable[CATEGORY] )
                    && MyTable[SUB-CATEGORY] = EARLIER ( MyTable[SUB-CATEGORY] )
            )
        )
    )

danextian_1-1654058628479.png

Here's the sample PBIX for your reference: https://drive.google.com/file/d/18FiQn-bj8k6jCmZDMK2xmp6Q88ttYL6s/view?usp=sharing 










Did I answer your question? Mark my post as a solution!


Proud to be a Super User!









"Tell me and I’ll forget; show me and I may remember; involve me and I’ll understand."
Need Power BI consultation, get in touch with me on LinkedIn or hire me on UpWork.
Learn with me on YouTube @DAXJutsu or follow my page on Facebook @DAXJutsuPBI.

Hi @danextian ,

 

Thanks for your help. It worked for me.

 

Thanks,

AshDil

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

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