Forum Discussion

Apprentice1000's avatar
Apprentice1000
New Member
5 years ago
Solved

Conditional column to pick up cell value above a particular cell

Hi, would appreciate help on this. I'm new to power query and trying to add a conditional column.

I need to grab the number above "Opening Balance" in column A (Our Ref)

This is the GL Code and it's too time consuming to fill this in manually. Thanks

 

Our RefAcc NoYour RefPr YrDateDue DateDescriptionDebitCredit
100, Interest Earned        
Opening Balance      00
BNK0001 Bank interest recvdApr/202130/04/2021 Bank interest 1.5
BNK0002 Bank interest recvdApr/202130/04/2021 Bank interest 0.2
      Totals.: 1.7
Closing Balance      01.7
         
110, Sales        
Opening Balance      00
SI000001CUST1JOB 00001Apr/20211/04/20211/05/2021Product description 123 200
SI000002CUST1JOB 00001Apr/20211/04/20211/05/2021Product description 124 100
SI000003CUST1JOB 00001Apr/20211/04/20211/05/2021Product description 125 300
SI000004CUST1JOB 00001Apr/20211/04/20211/05/2021Product description 126 400
SI000005CUST1JOB 00001Apr/20211/04/20211/05/2021Product description 127 500
SI000006CUST1JOB 00001Apr/20211/04/20211/05/2021Product description 128 600
SI000007CUST1JOB 00001Apr/20211/04/20211/05/2021Product description 129 700
SI000008CUST2BLAHBLAHApr/20211/04/202120/05/2021Product description 130  
SI000009CUST3SDFKJSDFApr/20211/04/20211/05/2021Product description 131 200
SI000010CUST4JOB NO1000Apr/20211/04/202120/05/2021Product description 132 200
SI000011CUST4JOB NO1000Apr/20211/04/202120/05/2021Product description 133 200
SI000012CUST551510200Apr/20211/04/202120/05/2021Product description 134 200
SI000013CUST551510200Apr/20211/04/202120/05/2021Product description 135 200
SI000014CUST551510200Apr/20211/04/202120/05/2021Product description 136 200
      Totals.: 4000
Closing Balance       4000
         
120, Purchases        
Opening Balance      00
PI00001VEND1I0000100Apr/20211/04/202120/05/2021Supplier invoice 1500 
PI00002VEND1I0000101Apr/20211/04/202120/05/2021Supplier invoice 22000 
PI00003VEND1I0000102Apr/20211/04/202120/05/2021Supplier invoice 31000 
      Totals.:3500 
Closing Balance      35000
  • You can try with this in New blank query and adjust steps to your source table.

     

    let
        Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("tdVPb4IwFADwr9JwNvraArrdRF2mLmqC28V4INhsZAQIoJ9/VF8X6h9GZj1UsGn7o6+v7WZjUYAOmSalyEVRkkmQJ2JndSzSWLadjbXMRBIln8QL4iAJRUN7OBbZx1vMAYBivRck3yRSdC7Cg5SHWd5jwGQjDj2w1Z+LHlhHu05tbGZ0bOiy49i3ZrZOyyAuus+/n9I/Nh/FadE+NKpXc8hV2Cmt1ssPYlE8bJX8KQAu0+jdX8vnbOkRVVcLIq3FsHp31PsqT3f7sCQ7UYR5lJVRmhDKOEoMNIeZdmy1HLrDTTsOOlx3bNOOi46tO45pp4+OozuuaWeAjqs7fdPOEzp93RmgI/POexu+ynKbYfCXw0Hbcag8oSKzzh+/zGfVzx2T4eqY0jcPBWRsDNpiWWU93DUddl2i5qXrBwJVB4JMcIc6FNidjn3d4aYd57pjm3bcM6fl9WQDtm9/P2ndWl5QrLqgVvs8/AqKB15Sq6k6Hz4mi7F84oZoG1p/n2VxJPLqzj+kUSgIxaNPfdVJYJdCw6HULLDTmp0T/JJg/yXkWLROtMgNXp91+9zAbtVybH8A", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [#"Our Ref" = _t, #"Acc No" = _t, #"Your Ref" = _t, #"Pr Yr" = _t, Date = _t, #"Due Date" = _t, Description = _t, Debit = _t, Credit = _t]),
        #"Added Index" = Table.AddIndexColumn(Source, "Index", 0, 1, Int64.Type),
        #"Added Custom" = Table.AddColumn(#"Added Index", "Number", each if Text.StartsWith(#"Added Index"[Our Ref]{[Index]+1},"Opening") then Text.BeforeDelimiter([Our Ref], ",") else null, type number )
    in
        #"Added Custom"

     

    ...or...

     

    let
        Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("tdVPb4IwFADwr9JwNvraArrdRF2mLmqC28V4INhsZAQIoJ9/VF8X6h9GZj1UsGn7o6+v7WZjUYAOmSalyEVRkkmQJ2JndSzSWLadjbXMRBIln8QL4iAJRUN7OBbZx1vMAYBivRck3yRSdC7Cg5SHWd5jwGQjDj2w1Z+LHlhHu05tbGZ0bOiy49i3ZrZOyyAuus+/n9I/Nh/FadE+NKpXc8hV2Cmt1ssPYlE8bJX8KQAu0+jdX8vnbOkRVVcLIq3FsHp31PsqT3f7sCQ7UYR5lJVRmhDKOEoMNIeZdmy1HLrDTTsOOlx3bNOOi46tO45pp4+OozuuaWeAjqs7fdPOEzp93RmgI/POexu+ynKbYfCXw0Hbcag8oSKzzh+/zGfVzx2T4eqY0jcPBWRsDNpiWWU93DUddl2i5qXrBwJVB4JMcIc6FNidjn3d4aYd57pjm3bcM6fl9WQDtm9/P2ndWl5QrLqgVvs8/AqKB15Sq6k6Hz4mi7F84oZoG1p/n2VxJPLqzj+kUSgIxaNPfdVJYJdCw6HULLDTmp0T/JJg/yXkWLROtMgNXp91+9zAbtVybH8A", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [#"Our Ref" = _t, #"Acc No" = _t, #"Your Ref" = _t, #"Pr Yr" = _t, Date = _t, #"Due Date" = _t, Description = _t, Debit = _t, Credit = _t]),
        #"Added Custom" = Table.AddColumn(Source, "Number", each try Number.From(Text.BeforeDelimiter([Our Ref], ",")) otherwise null, type number)
    in
        #"Added Custom"

     

1 Reply

  • Jakinta's avatar
    Jakinta
    Icon for Solution Sage rankSolution Sage

    You can try with this in New blank query and adjust steps to your source table.

     

    let
        Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("tdVPb4IwFADwr9JwNvraArrdRF2mLmqC28V4INhsZAQIoJ9/VF8X6h9GZj1UsGn7o6+v7WZjUYAOmSalyEVRkkmQJ2JndSzSWLadjbXMRBIln8QL4iAJRUN7OBbZx1vMAYBivRck3yRSdC7Cg5SHWd5jwGQjDj2w1Z+LHlhHu05tbGZ0bOiy49i3ZrZOyyAuus+/n9I/Nh/FadE+NKpXc8hV2Cmt1ssPYlE8bJX8KQAu0+jdX8vnbOkRVVcLIq3FsHp31PsqT3f7sCQ7UYR5lJVRmhDKOEoMNIeZdmy1HLrDTTsOOlx3bNOOi46tO45pp4+OozuuaWeAjqs7fdPOEzp93RmgI/POexu+ynKbYfCXw0Hbcag8oSKzzh+/zGfVzx2T4eqY0jcPBWRsDNpiWWU93DUddl2i5qXrBwJVB4JMcIc6FNidjn3d4aYd57pjm3bcM6fl9WQDtm9/P2ndWl5QrLqgVvs8/AqKB15Sq6k6Hz4mi7F84oZoG1p/n2VxJPLqzj+kUSgIxaNPfdVJYJdCw6HULLDTmp0T/JJg/yXkWLROtMgNXp91+9zAbtVybH8A", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [#"Our Ref" = _t, #"Acc No" = _t, #"Your Ref" = _t, #"Pr Yr" = _t, Date = _t, #"Due Date" = _t, Description = _t, Debit = _t, Credit = _t]),
        #"Added Index" = Table.AddIndexColumn(Source, "Index", 0, 1, Int64.Type),
        #"Added Custom" = Table.AddColumn(#"Added Index", "Number", each if Text.StartsWith(#"Added Index"[Our Ref]{[Index]+1},"Opening") then Text.BeforeDelimiter([Our Ref], ",") else null, type number )
    in
        #"Added Custom"

     

    ...or...

     

    let
        Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("tdVPb4IwFADwr9JwNvraArrdRF2mLmqC28V4INhsZAQIoJ9/VF8X6h9GZj1UsGn7o6+v7WZjUYAOmSalyEVRkkmQJ2JndSzSWLadjbXMRBIln8QL4iAJRUN7OBbZx1vMAYBivRck3yRSdC7Cg5SHWd5jwGQjDj2w1Z+LHlhHu05tbGZ0bOiy49i3ZrZOyyAuus+/n9I/Nh/FadE+NKpXc8hV2Cmt1ssPYlE8bJX8KQAu0+jdX8vnbOkRVVcLIq3FsHp31PsqT3f7sCQ7UYR5lJVRmhDKOEoMNIeZdmy1HLrDTTsOOlx3bNOOi46tO45pp4+OozuuaWeAjqs7fdPOEzp93RmgI/POexu+ynKbYfCXw0Hbcag8oSKzzh+/zGfVzx2T4eqY0jcPBWRsDNpiWWU93DUddl2i5qXrBwJVB4JMcIc6FNidjn3d4aYd57pjm3bcM6fl9WQDtm9/P2ndWl5QrLqgVvs8/AqKB15Sq6k6Hz4mi7F84oZoG1p/n2VxJPLqzj+kUSgIxaNPfdVJYJdCw6HULLDTmp0T/JJg/yXkWLROtMgNXp91+9zAbtVybH8A", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [#"Our Ref" = _t, #"Acc No" = _t, #"Your Ref" = _t, #"Pr Yr" = _t, Date = _t, #"Due Date" = _t, Description = _t, Debit = _t, Credit = _t]),
        #"Added Custom" = Table.AddColumn(Source, "Number", each try Number.From(Text.BeforeDelimiter([Our Ref], ",")) otherwise null, type number)
    in
        #"Added Custom"