Forum Discussion

hemann's avatar
hemann
Helper I
1 year ago
Solved

Cumulative Sum in Power Query

Hi,  I am trying to perform a cumulative sum in Power Query. Below is an example of the data and the deisred result. Can somebody please provide M language logic in Power Query to solve this.  Curr...
  • ryan_mayu's avatar
    1 year ago

    hemann 

    It looks like that the data is not accumulating by date. Not sure if this is what you want.

    If you want to accumulate by date, you can try this

     

    = Table.AddColumn(#"Added Index", "Custom", each List.Sum( Table.SelectRows(#"Added Index",(x)=>x[End of Month]<=[End of Month] and x[Attribute]=[Attribute] )[Value]))

     

    if just need to accumulate by the row order, you need to create a index column , then try this

     

    = Table.AddColumn(#"Added Custom", "Custom.1", each List.Sum( Table.SelectRows(#"Added Custom",(x)=>x[Index]<=[Index] and x[Attribute]=[Attribute] )[Value]))

     

     

    pls see the attachment below

    Cumulative Sum in Power Query.pbix44 KB