Forum Discussion

ITTom365's avatar
ITTom365
Brass Contributor
Oct 11, 2022
Solved

Excel power query calculated column offset cells

Hello,    I'm learning power query to replace VBA as the method of getting/transforming data for analysis in excel.    I am stuck with how to construct a query for a column that requires comparin...
  • Lorenzo's avatar
    Oct 11, 2022

    Hi ITTom365 

     

    Power Query isn't really designed to do this kind of things. In a nutshell you have to add an Index column and then reference the desired column/field* + the Index for the "row" number. In the attached example:

     

    after adding an Index, the Custom column formula:

    if [Amount] < 50
    then try [Amount] - #"Added Index"[Order]{[Index]-1} otherwise [Amount]
    else [Amount] * 10

    says something like:

    =IF([@Amount] < 50, IFERROR([@Amount] - OFFSET([@Order],-1,),[@Amount]), [@Amount] * 10)

     

    * Referencing Column-n without knowing its name is also possible...

     

Resources