Learn from the best! Meet the four finalists headed to the FINALS of the Power BI Dataviz World Championships! Register now
I need to make a custom column in power query. This excel formula =SE(E(N6>10; N6>T5); N6;T5), column N the table already has, however, column T would be the previous row of the column being created.
This solution is based on the previous row reference as described here (excellent read):
let
previousRow = (MyTable as table, MyColumnName as text) =>
let
Source = MyTable,
ShiftedList = {null} & List.RemoveLastN(Table.Column(Source, MyColumnName),1),
Custom1 = Table.ToColumns(Source) & {ShiftedList},
Custom2 = Table.FromColumns(Custom1, Table.ColumnNames(Source) & {"Previous Row"})
in
Custom2,
Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("Jc27DQAxDALQXahdnJPLbxbL+68RTLonJCACDsNCWqBRW+rUkX7KP3EUXZzFJq6itKmXHapLrBo3xDoaj/U0kXkB", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [N = _t, T = _t]),
#"Changed Type" = Table.TransformColumnTypes(Source,{{"N", Int64.Type}, {"T", Int64.Type}}),
Custom1 = previousRow(#"Changed Type","T"),
#"Added Custom" = Table.AddColumn(Custom1, "Custom", each if ([N] > 10 and [N] > [Previous Row]) then [N] else [Previous Row])
in
#"Added Custom"
My question is how to create a column that repeats the value of created column row whenever it is greater than 10?
This table is an example of the question. The column N has values I have but the T is the column I need to create.
| User | Count |
|---|---|
| 13 | |
| 9 | |
| 6 | |
| 5 | |
| 5 |