Hi @pedroccamara
So with your adjusted logic, I think this should do it.
There were dates out of scope, those will return a null value
let
Source = Excel.CurrentWorkbook(){[Name="FactTable"]}[Content],
ChType = Table.TransformColumnTypes(Source,{{"id", Int64.Type}, {"id_user", Int64.Type}, {"id_cliente", Int64.Type}, {"Date", type date}, {"horas_facturaveis", type logical}, {"Tempo", Int64.Type}, {"Valor", Int64.Type}}),
BufferedTable = Table.Buffer( Table.Sort( LookupTable,{{"Data inicio", Order.Ascending}} )),
GetValue = Table.AddColumn( ChType, "Value", each
try Table.LastN(
Table.SelectRows( BufferedTable, (BT)=> BT[Data inicio] <= [Date]),
1 ){0}[valor] otherwise null, type number
)
in
GetValue
.
Here’s your excel file incl. this query. Sample (1).xlsx (226.1 KB)
I hope this is helpful