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

Find everything you need to get certified on Fabric—skills challenges, live sessions, exam prep, role guidance, and more. Get started

Reply
Alex_0201
Post Partisan
Post Partisan

SUM function

Hi, I'm confused by SUM/SUMX formulas. I want to create a column called Total Time that:

- has 0 in the first row

- starting from the second row down every cell is a sum of a current value from a column called time and all the values from the rows above.

Easily done in Excel (=A2+B2), but can get it right in powerbi.

 

1.PNG

12 REPLIES 12
v-lili6-msft
Community Support
Community Support

hi @Alex_0201 

For your case, you need to add an index column first, then create a new column as below:

Total time, hrs = CALCULATE(SUM('Table'[time, hrs]),FILTER('Table','Table'[Index]<EARLIER('Table'[Index])))+0

Result:

3.JPG

 

And if you want show 191, that needs you create a measure to show it in visual, try this way as below:

Step1:

Add  Index table as below:

Index table = GENERATESERIES(1,MAX('Table'[Index])+1,1)

Step2:

Create a relationship by index column as below:

4.JPG

 

Step3:

Create a measure as below:

Total time, hrs = CALCULATE(SUM('Table'[time, hrs]),FILTER(ALL('Index table'),'Index table'[Index]<MAX('Index table'[Index])))+0

Result:

5.JPG

 

and here is sample pbix file, please try it.

 

Regards,

Lin

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

Hi @v-lili6-msft thanks for that! 

I've forgot to add a column called step_no. 

There is one problem, this measure adds new rows:

 

1.PNG

 

Original table visualization (target_duration is the time column in my post):

2.PNG

After adding the measure:

3.PNG

hi  @Alex_0201 

Could you please share your sample pbix file for us have a test? I will help you adjust it quickly.

 

Regards,

Lin

Community Support Team _ Lin
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
amitchandak
Super User
Super User

@Alex_0201 , You have add an index column

https://stackoverflow.com/questions/45715963/creating-an-index-column-for-power-bi

 

Cumm = CALCULATE(SUM(Table[time hrs]),filter(all(Table),Table[index] <=maxx(Table,Table[index])))

Hi @amitchandak  thanks for that! 

I've forgot to add a column called step_no. 

There is one problem, this measure/column adds new rows:

 

1.PNG

 

Original table visualization (target_duration is the time column in my post):

2.PNG

After adding the measure:

3.PNG

@Alex_0201 , Just check in visual table, does target duration has an aggregation, seem like do not summarize option on that. If so make it Sum.

@amitchandak changed it to Sum. The same result. 

@amitchandak can I create an index column that copies the column step no? If i just add the index column (from 1), the order is different from the order in step no

FrankAT
Community Champion
Community Champion

Hi @Alex_0201,

you are looking for the running total. You can accomplish it as follows (see figure):

 

25-06-_2020_16-28-12.jpg

 

Regards FrankAT

@FrankAT thank you! but is there a formula that can both add a row with 0 and then the running total, so it'd look like on the screenshot?

parry2k
Super User
Super User

@Alex_0201 now for running total, you have to have a column that defines the order in which you want to sum this running total, that column can be a date or index columns. Do you have something like that in your model? if not then add an index column in power query and then running total can be created.

 

I would  Kudos if my solution helped. 👉 If you can spend time posting the question, you can also make efforts to give Kudos whoever helped to solve your problem. It is a token of appreciation!

Visit us at https://perytus.com, your one-stop shop for Power BI related projects/training/consultancy.



Subscribe to the @PowerBIHowTo YT channel for an upcoming video on List and Record functions in Power Query!!

Learn Power BI and Fabric - subscribe to our YT channel - Click here: @PowerBIHowTo

If my solution proved useful, I'd be delighted to receive Kudos. When you put effort into asking a question, it's equally thoughtful to acknowledge and give Kudos to the individual who helped you solve the problem. It's a small gesture that shows appreciation and encouragement! ❤


Did I answer your question? Mark my post as a solution. Proud to be a Super User! Appreciate your Kudos 🙂
Feel free to email me with any of your BI needs.

@parry2k yes, I do. it's called Step No:

Capture.PNG

Helpful resources

Announcements
September Hackathon Carousel

Microsoft Fabric & AI Learning Hackathon

Learn from experts, get hands-on experience, and win awesome prizes.