Forum Discussion
Work with dates
- 3 years ago
Hi Alexandre,
now your code work 😉
I have written a query with the code (see below). I call this query in a custom column. It always finds the correct price!
Thanks for your help!!!
(FieldInput as datetime) => let qSource = Excel.CurrentWorkbook(){[Name="tbl_CostPerTime"]}[Content], qRow = Table.SelectRows(qSource, each ([ValidFromDate]<=FieldInput)), qContent= Table.Sort(qRow,{{"ValidFromDate", Order.Ascending}})[Value]{Table.RowCount(Table.Sort(qRow,{{"ValidFromDate", Order.Descending}})) - 1} in qContent
Hi Alexandre,
thank you for your help. Your suggestion does not quite work. As you can see in the screenshots, the date from which a price is valid is entered in the stored order, but not matching the start day of the loading process.
However, the prices must be assigned as follows:
- Charge start 20.02.2022, price from 01.01.2022
- Charge start 07.03.2022, price from 01.03.2022
- Charge start 12.09.2022, price from 01.09.2022
Result:
Result
Table with Prices:
User defined Column
Userdefined column
Is it possible that the runtime must be informed in line 4 from which table the column [ValidFromDate] comes?
Hello RalphHoffmann , you miss some adaptations to the function code:
Try to replace (row 6)
sorted = Table.Sort(filtered,{{"Date", Order.Ascending}})
by
sorted = Table.Sort(filtered,{{"ValidFromDate", Order.Ascending}})
And to replace (rows 8 & 9)
in tbl_CostPerTime
by
in price