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

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.

Reply
Jim_PBI
Frequent Visitor

Running total using sum with duplicate values in data

I'm trying to calculate a running total using sum which I've already been able to do. The issue is that my data contains duplicates that need to be handled by taking an average/min before I can calculate the running total. The duplicates must remain in the data. Please could somebody share how I can do this with DAX?

 

An example of my dataset is here 

 

Date ItemSold
04/09/2023Chair100
04/09/2023Chair100
04/09/2023Chair100
05/09/2023Chair150
05/09/2023Chair150
05/09/2023Chair150
06/09/2023Chair200
06/09/2023Chair200
06/09/2023Chair200
04/09/2023Sofa100
04/09/2023Sofa100
04/09/2023Sofa100
05/09/2023Sofa150
05/09/2023Sofa150
05/09/2023Sofa150
06/09/2023Sofa200
06/09/2023Sofa200
06/09/2023Sofa200

 

This is the expected result from the calculation

Date ItemRunning total
04/09/2023Chair100
05/09/2023Chair250
06/09/2023Chair450
04/09/2023Sofa100
05/09/2023Sofa250
06/09/2023Sofa450
1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi @Jim_PBI ,

 

According to your description, here are my steps you can follow as a solution.

(1) My test data is the same as yours.

(2) We can create a table.

 

 

New Table = 
SUMMARIZE(
'Table',
'Table'[Date],
'Table'[Item],
"AvgSold", AVERAGE('Table'[Sold])
)

 

 

(3)We can create measures.

 

 

Measure = 
VAR CurrentDate = MAX('New Table'[Date])
VAR CurrentItem = MAX('New Table'[Item])

RETURN
SUMX(
FILTER(
ALL('New Table'),
'New Table'[Date] <= CurrentDate
&& 'New Table'[Item] = CurrentItem
),
'New Table'[AvgSold]
)
Running total = SUMX(SUMMARIZE('New Table',[Date],[Item],"total",[Measure]),[total])

 

 

(4) Then the result is as follows.

vtangjiemsft_1-1696215859233.png

 

 

Best Regards,

Neeko Tang

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
Anonymous
Not applicable

Hi @Jim_PBI ,

 

According to your description, here are my steps you can follow as a solution.

(1) My test data is the same as yours.

(2) We can create a table.

 

 

New Table = 
SUMMARIZE(
'Table',
'Table'[Date],
'Table'[Item],
"AvgSold", AVERAGE('Table'[Sold])
)

 

 

(3)We can create measures.

 

 

Measure = 
VAR CurrentDate = MAX('New Table'[Date])
VAR CurrentItem = MAX('New Table'[Item])

RETURN
SUMX(
FILTER(
ALL('New Table'),
'New Table'[Date] <= CurrentDate
&& 'New Table'[Item] = CurrentItem
),
'New Table'[AvgSold]
)
Running total = SUMX(SUMMARIZE('New Table',[Date],[Item],"total",[Measure]),[total])

 

 

(4) Then the result is as follows.

vtangjiemsft_1-1696215859233.png

 

 

Best Regards,

Neeko Tang

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

eliasayyy
Memorable Member
Memorable Member

hello @Jim_PBI  first get the unique value of date using max or average if all data are the same the average should return the same number 
so UniqueDailyAverage = CALCULATE(AVERAGE('Table'[Sold]))
then use a sumx function 

Running Total =
SUMX(
FILTER(
ALLSELECTED('Table'),
'Table'[Date] <= MAX('Table'[Date])
&& 'Table'[Item] = MAX('Table'[Item])
),
'Table'[UniqueDailyAverage]
)

OR

create a new calculate table using summarize to get unqiue values

AggregatedTable =
SUMMARIZE(
'OriginalTable',
'OriginalTable'[Date],
'OriginalTable'[Item],
"AvgSold", AVERAGE('OriginalTable'[Sold])
)

now just create emasure

Running Total =
VAR CurrentDate = MAX('AggregatedTable'[Date])
VAR CurrentItem = MAX('AggregatedTable'[Item])

RETURN
SUMX(
FILTER(
'AggregatedTable',
'AggregatedTable'[Date] <= CurrentDate
&& 'AggregatedTable'[Item] = CurrentItem
),
'AggregatedTable'[AvgSold]
)



Helpful resources

Announcements
July 2025 community update carousel

Fabric Community Update - July 2025

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

July PBI25 Carousel

Power BI Monthly Update - July 2025

Check out the July 2025 Power BI update to learn about new features.