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

Calling all Data Engineers! Fabric Data Engineer (Exam DP-700) live sessions are back! Starting October 16th. Sign up.

Reply
Pranali_R
Frequent Visitor

How to Calculate the Sum/count till selected date

 I am trying to write a dax to calculate sum of the records. But the sum only takes the latest record for each "Name"

Example : 

I have input as 3 columns Name, Type and Valueupdateddate 

JenniferWallace_1-1671536089466.png

For CP123, Value updated date = 20 Jan 2021, type = manual , and it changed in Feb 2022 i.e, type=automatic , so when calculated for Jan 2022 it should still consider the "Type"  as manual as at that point in time the "Type" was manual.

When I select filter as July 2022. My output table should be. So it should also consider the values if the type has changed.

JenniferWallace_2-1671536122804.png

 

Can you please help!.

Thanks😊

3 REPLIES 3
tamerj1
Super User
Super User

Hi @Pranali_R 

you need a 'Date' table linked with the main 'Table' then you can use a matrix visual, place 'Date'[Month-Year] in the columns and 'Table']Type] in the rows then place the following measure in the values

Count =
VAR CurrentDate =
MAX ( 'Date'[Date] )
VAR CurrentNames =
CALCULATETABLE ( VALUES ( 'Table'[Name] ), ALL ( 'Date' ) )
RETURN
SUMX (
CurrentNames,
VAR MaxDate =
CALCULATE (
MAX ( 'Table'[Value_Updated Date] ),
ALL ( 'Table'[Type] ),
ALL ( 'Date' )
)
VAR ThisDate =
CALCULATE ( MAX ( 'Table'[Value_Updated Date] ), ALL ( 'Date' ) )
RETURN
IF ( ThisDate <= CurrentDate && ThisDate >= MaxDate, 1 )
)

 

Pranali_R
Frequent Visitor

@MAwwad It is not a cumulative sum ..If you see the output, it is not increasing, if the type changes, the number decreases.

Here is the sample data. 

NameTypeValue_Updated DateLatest Record?
CP123Manual20-Jan-21No
CP123Automatic21-Feb-22Yes
CP124Manual20-Jan-21No
CP124Automatic05-Apr-22No
CP124Manual07-Apr-22Yes
CP130Manual17-Oct-21No
CP130Automatic01-Dec-21Yes
CP138Automatic09-Apr-22No
CP138Manual09-Jun-22Yes
MAwwad
Solution Sage
Solution Sage

To create a cumulative sum in DAX (Data Analysis Expression) language, you can use the SUMX function, which iterates over a table and calculates a running sum of the expression provided.

 

For example, to calculate a cumulative sum of the "Value" column for a table with the input columns "Name", "Type", and "Valueupdateddate", you could use the following DAX formula:

CumulativeSum = SUMX ( FILTER ( TableName, TableName[Valueupdateddate] <= MAX ( TableName[Valueupdateddate] ) ), TableName[Value] )

 

This formula filters the table to only include rows with a "Valueupdateddate" less than or equal to the maximum "Valueupdateddate" in the table, and then calculates a running sum of the "Value" column.

If you want to further filter the table by a specific date range, such as July 2022, you can modify the formula to include an additional filter on the "Valueupdateddate" column, like this:

CumulativeSum = SUMX ( FILTER ( TableName, TableName[Valueupdateddate] <= MAX ( TableName[Valueupdateddate] ) && TableName[Valueupdateddate] >= DATE ( 2022, 7, 1 ) && TableName[Valueupdateddate] <= DATE ( 2022, 7, 31 ) ), TableName[Value] )

 

This formula filters the table to only include rows with a "Valueupdateddate" in July 2022, and then calculates a running sum of the "Value" column.

Helpful resources

Announcements
FabCon Global Hackathon Carousel

FabCon Global Hackathon

Join the Fabric FabCon Global Hackathon—running virtually through Nov 3. Open to all skill levels. $10,000 in prizes!

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.