Reputation: 9
im new to power bi.
I searched all around but couldn't find an answer to this problem.
I have a column of values that I want to plot two line graphs, first would be a graph of occurrences on a time bin of 30 minutes and the other would be an acumulative during the day.
I can make the time bin part work but I just can't make the acumulative part work on a time column. I tried everything that I could but it only work with dates and not times, so when I put the time values it just repeat the value of the time bin count.
This is what i get:
Cumulative should be [482,819,1092,1349...109381]
This is what I have:
And this is what i need:
Thanks in advance for your time!
Upvotes: 0
Views: 86
Reputation: 12167
I assume you have the following tblData
within Power Query as input for the function fnRunningSum
(I will add the M-code at the end of the post).
If you use this table as input for fnRunningSum
you will get a table with a cumulative sum which I guess you are after
The code for fnRunningSum
is
(MyTable as table) as table =>
let
Source = Table.Buffer(MyTable),
TableType = Value.Type(Table.AddColumn(Source, "Running Sum", each null, type number)),
Cumulative = List.Skip(List.Accumulate(Source[Wert],{0},(cumulative,wert) => cumulative & {List.Last(cumulative) + wert})),
AddedRunningSum = Table.FromColumns(Table.ToColumns(Source)&{Cumulative},TableType)
in
AddedRunningSum
PS Another version could be to shorten it to this code just for the input table tbldata
let
Quelle = tblData,
#"Hinzugefügte benutzerdefinierte Spalte" = Table.AddColumn(Quelle, "SumList", each List.Skip(List.Accumulate(Quelle[Wert],{0},(cumulative,wert) => cumulative & {List.Last(cumulative) + wert}))),
#"Hinzugefügter Index" = Table.AddIndexColumn(#"Hinzugefügte benutzerdefinierte Spalte", "Index", 0, 1, Int64.Type),
#"Hinzugefügte benutzerdefinierte Spalte1" = Table.AddColumn(#"Hinzugefügter Index", "RunningTotal", each [SumList]{[Index]}),
#"Entfernte Spalten" = Table.RemoveColumns(#"Hinzugefügte benutzerdefinierte Spalte1",{"SumList", "Index"})
in
#"Entfernte Spalten"
Upvotes: 1