Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
6 years ago
Solved

How to refer previous cell for this case ?

hello,   I am working on moving excel sheet work to power pibot/query. I have faced this issue while I am editing the data on power query editor.   Excel formula: =IF(B3=B2,C2,"First")   How ...
  • Anonymous's avatar
    Anonymous
    6 years ago

    Here's how to do it. Please insert this piece of code into the Editor in PQ and inspect each step.

    let
        Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("bdDLCQAwCAPQXTz30n93ke6/RoMUApJD4UHViO52rODd4ragFWpQC21ohyY0kwY0Ul2FavqlmMYMVdehnsRclcHJFHvVfmqeSuNd1H7qQn/efQ==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type text) meta [Serialized.Text = true]) in type table [B = _t, C = _t]),
        #"Changed Type" = Table.TransformColumnTypes(Source,{{"B", Int64.Type}, {"C", Int64.Type}}),
        #"Added Index" = Table.AddIndexColumn(#"Changed Type", "Index", 0, 1),
        #"Changed Type1" = Table.TransformColumnTypes(#"Added Index",{{"Index", Int64.Type}}),
        #"Reordered Columns" = Table.ReorderColumns(#"Changed Type1",{"Index", "B", "C"}),
        Buferred  = Table.Buffer(#"Reordered Columns"),
        #"Added Custom" = 
            Table.AddColumn(#"Reordered Columns", "Previous Row", 
                (r) => Table.SelectRows(Buferred, (tbl) => tbl[Index] = r[Index] - 1)
            ),
        #"Expanded Previous Row" = Table.ExpandTableColumn(#"Added Custom", "Previous Row", {"B"}, {"Previous Row.B"}),
        #"Added Conditional Column" = Table.AddColumn(#"Expanded Previous Row", "Output", each if [B] = [Previous Row.B] then [C] else "First"),
        #"Removed Columns" = Table.RemoveColumns(#"Added Conditional Column",{"Index", "Previous Row.B"})
    in
        #"Removed Columns"

    Once you know what it does, use it to your advantage.

     

    Best

    D