Forum Discussion
donpep0
3 years agoFrequent Visitor
Repeat steps multiple times over the same table
Hi all! I'm a little stuck whit power Query, I'm trying to repeat multiple steps over the same table. My input(Source) looks like this: Date Index Volume 9/01 1 1100 9/02 2 1...
KT_Bsmart2gethe
3 years agoImpactful Individual
Hi donpep0 ,
An alternate approach to the situation. I am using Replace.Value instead of List.Accumulate.
Also, I don't use the index column.
Starting Point:
Code:
let
Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("NczBDQAhCETRVjacTRRRlFqM/bexgJnDvzwmnENcrfZOhTji1uiWQx2aF7aZKlAJFUscwBHYWFIndHq631cFaqRvuYDLS9mQ7X1JBrJH9wc=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Date = _t, Index = _t, Volume = _t]),
#"Changed Type" = Table.TransformColumnTypes(Source,{{"Date", type date}, {"Index", Int64.Type}, {"Volume", Int64.Type}}),
//Replace null with average of previous four periods
#"Replaced Value" = Table.ReplaceValue(
#"Changed Type",
each null,
each
let
LastFourPeriods = Table.SelectRows(
#"Changed Type",
(x)=> x[Date] < [Date] and x[Date] >= Date.AddDays([Date], -4)
)[Volume],
FourPeriodAverage = List.Average(
List.RemoveNulls(LastFourPeriods)
)
in
FourPeriodAverage,
Replacer.ReplaceValue,
{"Volume"}
)
in
#"Replaced Value"
Outcome:
Regards
KT