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

Earn a 50% discount on the DP-600 certification exam by completing the Fabric 30 Days to Learn It challenge.

Reply
Anonymous
Not applicable

How to acumulate values of a column

Hi,

 

I have a coulmn with decimal values, and I want to create a calculated column that will be the cumulative of that column. For example: 

Column 1   cumulative

1,65                1,65

1,65                3,3

0,33                3,63

0,66                4,29

 

Any tips on how to accomplish this? Thanks!

1 ACCEPTED SOLUTION
v-shex-msft
Community Support
Community Support

Hi @Anonymous,

 

If your table contains index column, it is possible to get the running total based on index column.

 

Sample: calculate column

Running Total = 
SUMX (
    FILTER ( ALL ( Test ), Test[Index] <= EARLIER ( Test[Index] ) ),
    [Value]
)

4.PNG

 

Regards,

Xiaoxin Sheng

Community Support Team _ Xiaoxin
If this post helps, please consider accept as solution to help other members find it more quickly.

View solution in original post

3 REPLIES 3
v-shex-msft
Community Support
Community Support

Hi @Anonymous,

 

If your table contains index column, it is possible to get the running total based on index column.

 

Sample: calculate column

Running Total = 
SUMX (
    FILTER ( ALL ( Test ), Test[Index] <= EARLIER ( Test[Index] ) ),
    [Value]
)

4.PNG

 

Regards,

Xiaoxin Sheng

Community Support Team _ Xiaoxin
If this post helps, please consider accept as solution to help other members find it more quickly.

A Power Query solution would be:

 

let
    #"**** QUERY SUMMARY ***" =
        "This query adds a column with the accumulation of the value in column ""Column 1"".#(lf)" &
        "A buffered list is created from the values.#(lf)" &
        "Using List.Accumulate, the values are accumulated.#(lf)" &
        "The initial value (the ""seed"" parameter of List.Accumulate) is a list with 1 item: {0}#(lf)" &
        "With each iteration, the value (v) is added to the last item of the cumulated list (c) and#(lf)" &
        "the result is concatenated to the cumulated list.#(lf)" &
        "After accumulation, the first element {0} is skipped.#(lf)" &
        "The resulting list is added to the table by transforming the table into columns (a list of lists),#(lf)" &
        "the list of accumulated values is added to this list of lists,#(lf)" &
        "the result is transformed to a table (using Table.FromColumns).#(lf)" &
        "This table gets the table type from the Source Table, to which the column ""Cumulative"" is added with dummy value 1:#(lf)" &
        "that additional column is only required for the column name and column type.",
    Source = Table1,
    NumberList = List.Buffer(Source[Column 1]),
    Cumulative = List.Skip(List.Accumulate(NumberList,{0},(c,v) => c & {(List.Last(c)+v)})),
    AddCumulativeToSource = 
        Table.FromColumns(Table.ToColumns(Source)&{Cumulative},
                          Value.Type(Table.AddColumn(Source,"Cumulative", each 1, type number)))
in
    AddCumulativeToSource
Specializing in Power Query Formula Language (M)
Anonymous
Not applicable

Thank you, @MarcelBeug. I'm still learning power query language, so your code is a bit difficult for me, but thanks.

Helpful resources

Announcements
RTI Forums Carousel3

New forum boards available in Real-Time Intelligence.

Ask questions in Eventhouse and KQL, Eventstream, and Reflex.

LearnSurvey

Fabric certifications survey

Certification feedback opportunity for the community.