cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
michaelmichael
Helper I
Helper I

Issues with CALCULATE (SUM)

Hi, I'm trying to get a columbn to SUM all the values for a given code, in every row that code is in. See below example

 

But the issue is my formula I'm using keeps giving just the SUM of the one row every time

 

Any help is much appreciated

 

Test = CALCULATE( SUM( Table[Value]), Table[Code] = Table[Code] )

 

CodeValueActual ResponseRequired Response
A226
A226
A226
B224
B224
C228
C228
C228
C228
D224
D224
1 ACCEPTED SOLUTION
AlexisOlson
Super User
Super User

Here are a couple of additional alternatives:

Test =
VAR _Code = Table[Code]
RETURN
    CALCULATE ( SUM ( Table[Value] ), Table[Code] = _Code )

 

Test =
CALCULATE ( SUM ( Table[Value] ), ALLEXCEPT ( Table, Table[Code] ) )

View solution in original post

4 REPLIES 4
AlexisOlson
Super User
Super User

Here are a couple of additional alternatives:

Test =
VAR _Code = Table[Code]
RETURN
    CALCULATE ( SUM ( Table[Value] ), Table[Code] = _Code )

 

Test =
CALCULATE ( SUM ( Table[Value] ), ALLEXCEPT ( Table, Table[Code] ) )
michaelmichael
Helper I
Helper I

@DimaMD thanks - that works for some, but a lot of the codes are adding up as they go, so onlt the last code in the table has the full total - Is there a better function that EARLIER() ??

I got past this by adding another column that gives the MAX result. Ideally I'd like to avoid having 2 columns

DimaMD
Responsive Resident
Responsive Resident

hi @michaelmichael  If you use this in the count column, try this code

CALCULATE(SUM('Лист1'[Value]),'Лист1'[Code] = EARLIER('Лист1'[Code]))

 Screenshot_9.jpg

Helpful resources

Announcements
August 1 episode 9_no_dates 768x460.jpg

The Power BI Community Show

Watch the playback when Priya Sathy and Charles Webb discuss Datamarts! Kelly also shares Power BI Community updates.

Power BI Dev Camp Session 24 without aka link and time 768x460.jpg

Ted's Dev Camp - July 28, 2022

Watch Session 24 of Ted's Dev Camp along with past sessions!

Power Platform Conf 2022 768x460.jpg

Join us for Microsoft Power Platform Conference

The first Microsoft-sponsored Power Platform Conference is coming in September. 100+ speakers, 150+ sessions, and what's new and next for Power Platform.

Top Solution Authors
Top Kudoed Authors