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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
Anonymous
Not applicable

Create table resulting from the analysis of another table

Hi everyone!

 

I'm trying to move my excel skills into PowerBI for profesionnal reasons.

 

Here is my case : I have a table of Non Conformity with creation and closure date columns. My goal is to know the quantity of opened Non Conformity at a given time. Exemple : "On the 1st february, we had 20 non conformity opened, but on the 5st, we had 75 opened -> What happened?'. The final goal is to draw the curve with time on X axis and quantity of Non conformity opened in Y axis.

 

To me, I need to create a table with Date, Non conformity ID and Status of the non conformity at that same date.

 

Why I am struggling : I perfectly know how to do that in VBA using loops, but I can't figure out how M language works for this kind of situation, despite all the artcles I read on the subject so far… I've to admit that I'm still using the basic button to transform my data in PowerBI instead of dealing with the M language directly, and this must changes 🙂

 

Thanks for you help! Alexis

1 ACCEPTED SOLUTION
artemus
Microsoft Employee
Microsoft Employee

(tbl as table, col as text, newCol as text) as table => 
   let 
      range = {0 .. Table.RowCount(tbl)},
      runningTotal = List.Accumulate(range, {}, (current, next) => current & {List.Last(current,  0) + Record.Field(tbl{next}, col)}),
      asTable = Table.FromList(runningTotal, each {_}, 1, {newCol}),
      joinTable = Table.AddIndexColumn(asTable, "t_index_join"),
      withIndexColumn = Table.AddIndexColumn(tbl, "t_index"),
      joined = Table.Join(withIndexColumn, "t_index", joinTable, "t_index_join"),
      removedTempCols = Table.RemoveColumns(joined, {"t_index", "t_index_join"})
   in
      removedTempCols

Here is how you do a running sum as a function

View solution in original post

1 REPLY 1
artemus
Microsoft Employee
Microsoft Employee

(tbl as table, col as text, newCol as text) as table => 
   let 
      range = {0 .. Table.RowCount(tbl)},
      runningTotal = List.Accumulate(range, {}, (current, next) => current & {List.Last(current,  0) + Record.Field(tbl{next}, col)}),
      asTable = Table.FromList(runningTotal, each {_}, 1, {newCol}),
      joinTable = Table.AddIndexColumn(asTable, "t_index_join"),
      withIndexColumn = Table.AddIndexColumn(tbl, "t_index"),
      joined = Table.Join(withIndexColumn, "t_index", joinTable, "t_index_join"),
      removedTempCols = Table.RemoveColumns(joined, {"t_index", "t_index_join"})
   in
      removedTempCols

Here is how you do a running sum as a function

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

December 2025 Power BI Update Carousel

Power BI Monthly Update - December 2025

Check out the December 2025 Power BI Holiday Recap!

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.