Excel Power Query Select value from previous row

dicken

Active Member
Joined
Feb 12, 2022
Messages
292
Office Version
  1. 365
Platform
  1. Windows
Hi
I've been trying to use Table.SelectRows to get a value from the previous row, I've got as far as a list of values,

Excel Formula:
= Table.AddColumn(#"Changed Type", "Custom",  (A)=>

 Table.SelectRows( #"Changed Type" ,(B)=> B[Date] < A[Date] )[Units]  )

Which returns a list of the units 0 in first 1 item in second 2 items in third position, I've been trying to return the first list item for row 1, second list item for row 2 and so on, I thought of
l
Code:
 } )

It may not be possible I'd be interested in any ideas,



1667742053127.png


1667742086759.png
So here I wold like to just have the second item from the list 3.

Richard.
 

Excel Facts

What is the shortcut key for Format Selection?
Ctrl+1 (the number one) will open the Format dialog for whatever is selected.
An example

Power Query:
let
    Source = Table.FromColumns({{0..9}, List.Dates(#date(2022,10,28), 10,#duration(2,0,0,0))}, {"Index", "Date"}),
    Result = Table.AddColumn(Source, "Previous Date", each try Source{[Index]-1}[Date] otherwise null)
in
    Result
 
Upvote 0
Solution
An example

Power Query:
let
    Source = Table.FromColumns({{0..9}, List.Dates(#date(2022,10,28), 10,#duration(2,0,0,0))}, {"Index", "Date"}),
    Result = Table.AddColumn(Source, "Previous Date", each try Source{[Index]-1}[Date] otherwise null)
in
    Result
Thanks,
RD
 
Upvote 0
An example

Power Query:
let
    Source = Table.FromColumns({{0..9}, List.Dates(#date(2022,10,28), 10,#duration(2,0,0,0))}, {"Index", "Date"}),
    Result = Table.AddColumn(Source, "Previous Date", each try Source{[Index]-1}[Date] otherwise null)
in
    Result
Thanks again, it's much more simple ( in a good way) than many, and no need for multiple index columns and merging,
the two way looking up in pq is something where I'm alway putting things in the wrong place or forgetting braces,

RD
 
Upvote 0

Forum statistics

Threads
1,223,516
Messages
6,172,778
Members
452,477
Latest member
DigDug2024

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top