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
Z4m
Frequent Visitor

SUMIF Calculate SUM based on subset of Collumns

I have a challenge on a Specific DAX formula.
I have one tabel containing A CustomerID, Week and a Value. I would like to add a Calculated Collumn that sums the Value of the Specific Customer in the Same Week. 
It should look like the result below;

Cust | Week | Value | SUM

A      |    1     |   2,5  | 6,5

A      |    1    |    4     | 6,5
A      |    2     |   2,5  | 5

A      |    2     |   2,5  | 5
B      |    1     |   5     | 6

B      |    1     |   2     | 6

B      |    2     |   5     | 10
B      |    2    |   5      | 10
C      |   1      |   8     |  8
C      |    2     |   8     |  8
C      |   3      |   8     | 8

C      |   4      |   8     | 8

I've treid using CALCULATE, SUM and SUMX but i wasn't albe to create the above results. 
I've also read different items on the "SUMIF" function but i couldn't find a way of sum that checks 2 identifying collumns (Cust. and Week)

I hope that someone could help me on this matter?

1 ACCEPTED SOLUTION
Vvelarde
Community Champion
Community Champion

hi @Z4m

 

You can do it with this calculated column:

 

SUMAPORCUSTOMERPORWEEK =
CALCULATE (
    SUM ( 'Table-Customer'[Value] );
    ALLEXCEPT (
        'Table-Customer';
        'Table-Customer'[Customer];
        'Table-Customer'[Week]
    )
)
 
This sum the value for each customer & weeks.



Lima - Peru

View solution in original post

6 REPLIES 6
Eric_Zhang
Employee
Employee

@Z4m

 

you can also try a DAX expression as

SUM =
SUMX (
    FILTER (
        'Table',
        EARLIER ( 'Table'[Cust] ) = 'Table'[Cust]
            && EARLIER ( 'Table'[Week] ) = 'Table'[Week]
    ),
    'Table'[Value]
)

Capture.PNG

@Eric_Zhang The solution you gave resulted in a cullumative collumn, i got it solve by another post.
But thanks for your advice!

kcantor
Community Champion
Community Champion

@Z4m

Why not just create a simple sum and use your week numbers from your date table? Put week numbers on a row then add customer ID. Use your sum for the values. One sum expression could then be used in multiple iterations.





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

Proud to be a Super User!




Vvelarde
Community Champion
Community Champion

hi @Z4m

 

You can do it with this calculated column:

 

SUMAPORCUSTOMERPORWEEK =
CALCULATE (
    SUM ( 'Table-Customer'[Value] );
    ALLEXCEPT (
        'Table-Customer';
        'Table-Customer'[Customer];
        'Table-Customer'[Week]
    )
)
 
This sum the value for each customer & weeks.



Lima - Peru
SamLester
Employee
Employee

There's likely a way to do this in DAX that I haven't learned yet, but one option in Power BI is to create a new table (Modeling -> New Table) with the following formula:

 

NewTable = SUMMARIZE('OriginalTable', 'OriginalTable'[Cust], 'OriginalTable'[Week], "Sum of Values" , SUM('OriginalTable'[Value]))

 

This will add the additional column that sums the VALUE column based on grouping of Customer and Week Number. You can then build a visual based on NewTable columns Cust, Week, and Sum of Values to get the results you've provided.

 

CustWeekValue.PNG

 

Thanks,
Sam Lester (MSFT)

ianbarker
Helper III
Helper III

Not really sure I get what you're trying to do, but would something like IF([Customer ID] = X,SUM([Value],Something else)) where X is the particular customer id?

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.