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

Join us for an expert-led overview of the tools and concepts you'll need to become a Certified Power BI Data Analyst and pass exam PL-300. Register now.

Reply
kcdistiller
Frequent Visitor

Calculate Running Total Using Input from Another Calculation (Measure)

There are many solutions to calculate a running total based on dates or counts within a table, but I have not found a way to create a running total measure using input from another measure. Consider the following visualization table:

 

Column AColumn BColumn CColumn D
Unique_ID (table data)Medication (table data)Percent_Contributed (calculated)Percent_Running_Total (desired calculation: same row, column C + prior row, column D)
7980Penicillin G17.7717.77
723Amoxicillin5.7923.56
2670Codeine4.2327.79
1191Aspirin2.4930.28
10831SMZ/TMP2.4732.75
7052Morphine2.3735.12

 

Columns A and B are text fields identifying unique items. Column C is a measure resulting from a calculated numerator and denominator [(amount for unique entry/amount for all unique entries) * 100]. 

 

I'm trying to use a measure to populate Column D in a visualization table with a running total using info from Column C, but all methods appear to rely on info in the data table(s).

5 REPLIES 5
CheenuSing
Community Champion
Community Champion

Hi @kcdistiller

 

It is possible to do it without a calendar table also.

 

I am assuming your UniqueID ( Column A) and Medication Data ( Column B) are coming from the same table.

 

Try this for column D , where you need the running total of column C

 

Define a measure RunningTotC 

 

RunningTotC =  Calculate([measureCoumnC],
                                                        FIlter(

                                                                    ALL(SourceDataTable),
                                                                          (SourceDataTable[ColumnA])<=MAX(SourceDataTable[CoulmnA])
                                                                  )

                                                                     )

 

 

The highlighted area above can also be changed to take a concatenation of Column A and Column B

as 

  ( SourceDataTable[ColumnA]&"-"&SourceData[ColumnB]<=MAX(SourceDataTable[ColumnA]&"-"&SourceData[ColumnB])

 

If this works for you please accept it as a solution and also give KUDOS.

 

Cheers

 

CheenuSing

Did I answer your question? Mark my post as a solution and also give KUDOS !

Proud to be a Datanaut!

Your suggestion calculates something, but not what is expected. If there is a way to use 'EARLIER' in place of 'MAX' in your recommended code, I think it would work. However, I get an error saying that "'EARLIER' refers to a row context which dosen't exist'. This is likely due to 'Percentage' being a measure, not an actual value in a table. If I change the measure to a calculated column, I lose the ability to update the value based on slicers. Ideally, the code would probably look like

 

RunningTotC = CALCULATE([Percentage],Filter(ALL('My Table'),('My Table'[Percentage])>=EARLIER('My Table'[Percentage])))

where 'Percentage' is the result of the measure in Column C, but 'EARLIER' does not work with measures.

GilbertQ
Super User
Super User

hi @kcdistiller

 

In terms of your data, does it have any dates associated with it?

 

If you have got a date, then you can easily create an interim calculated measure which will be the previous dates value.

NOTE: You will need a date table and create a relationship between the tables for this to work.

 

The example below is getting the values for the Previous Day.

 

Previous Row Data = 
CALCULATE (
    [Actuals],
        PARALLELPERIOD ( 'Date'[Calendar Date], -1, DAY ),
    )

And then your running total could be [Column D] + [Previous Row Data]





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

Proud to be a Super User!







Power BI Blog

Most solutions that I've found use dates, but there are no dates associated with my data.

CheenuSing
Community Champion
Community Champion

Hi @kcdistiller

 

Can you post sample data on oneDrive or Drop box to arrive ata solution.

 

Also post the formula you have used for measure ColumnC

 

 

Cheers

 

CheenuSing

 

Did I answer your question? Mark my post as a solution and also give KUDOS !

Proud to be a Datanaut!

Helpful resources

Announcements
Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

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

June 2025 community update carousel

Fabric Community Update - June 2025

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