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

Earn a 50% discount on the DP-600 certification exam by completing the Fabric 30 Days to Learn It challenge.

Reply
sebasplas313
New Member

Add column with sum of values based on a category

 Hi community,

I would like to know how i can add a column that has the total based on two columns. In this example i have in the first column, the name of the category, the second column the number of products and in the third, the sum of each category.

Column 1Column 2Column 3
A26
A16
A36
B510
B510

My question will be the dax or power query of how i can add this third column

 

Need help , Data help and tips , Free intermediate tutorials? 

Thanks,

Sebastian

1 ACCEPTED SOLUTION
v-zhangti
Community Support
Community Support

Hi, @sebasplas313 

 

Please check the following methods.

1. Dax
Column:

Column 3 = 
CALCULATE (
    SUM ( 'Table'[Column 2] ),
    FILTER ( 'Table', [Column 1] = EARLIER ( 'Table'[Column 1] ) )
)

vzhangti_0-1659339651420.png

 

2. Power Query

First copy the table into table2 in the power query.

vzhangti_1-1659339826746.png

vzhangti_2-1659339851356.png

Merge table2. in the original table and expand the new column.

vzhangti_3-1659339941987.png

vzhangti_4-1659340032166.png

Is this the result you expect?

 

Best Regards,

Community Support Team _Charlotte

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
v-zhangti
Community Support
Community Support

Hi, @sebasplas313 

 

Please check the following methods.

1. Dax
Column:

Column 3 = 
CALCULATE (
    SUM ( 'Table'[Column 2] ),
    FILTER ( 'Table', [Column 1] = EARLIER ( 'Table'[Column 1] ) )
)

vzhangti_0-1659339651420.png

 

2. Power Query

First copy the table into table2 in the power query.

vzhangti_1-1659339826746.png

vzhangti_2-1659339851356.png

Merge table2. in the original table and expand the new column.

vzhangti_3-1659339941987.png

vzhangti_4-1659340032166.png

Is this the result you expect?

 

Best Regards,

Community Support Team _Charlotte

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

VahidDM
Super User
Super User

Hi @sebasplas313 

 

Try this DAX expression to add a new calculated column to your table:

 

Column 3 DAX = 
CALCULATE (
    SUM ( 'Table (2)'[Column 2] ),
    REMOVEFILTERS ( 'Table (2)'[Column 2] )
)

 

 

Output:

VahidDM_0-1658877408991.png

 

 

 

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

Appreciate your Kudos!! 

Badges.jpg

LinkedIn | Twitter | Blog | YouTube 

Helpful resources

Announcements
RTI Forums Carousel3

New forum boards available in Real-Time Intelligence.

Ask questions in Eventhouse and KQL, Eventstream, and Reflex.

MayPowerBICarousel

Power BI Monthly Update - May 2024

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

LearnSurvey

Fabric certifications survey

Certification feedback opportunity for the community.