March 13, 2022
Hello . Your site is very useful. We have two ranges in the attachment. In the first range, the four columns are completely full and in the second range, the last column is empty. What is the 9000 number recognition algorithm? The p .Code & SRC columns are exactly equal, and we need to move the corresponding rate to the second range after finding the date that is less than or equal to the date in the first range, as you can see in the example.
(Here is the solar date or Persian and the "/" sign is removed from the year, month and day to be numbered [Explanation: Microsoft Office does not support solar date]). I want this issue to be resolved using PowerQuery. Because I can do it in VBA
Moderators
January 31, 2022
Moderators
January 31, 2022
March 13, 2022
Hello again . Thank you very much for your reply, Mr. Riny van Eekelen. And of course the site staff who have provided this opportunity.I may not have used the right words to say thank you. I use Google Translator to write
I wanted to ask members to write other ways to solve the problem
March 13, 2022
The following code is exactly what I wanted. A friend like Mr. Riny van Eekelen helped me get this code
let
//Read in the lookup table
Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
lookupTable = Table.TransformColumnTypes(Source,{
{"Date", Int64.Type},
{"P.Code",Int64.Type},
{"SRC", Int64.Type},
{"Rate", Int64.Type}
}),
//read in data table
Source2 = Excel.CurrentWorkbook(){[Name="Table2"]}[Content],
typeIt2 = Table.TransformColumnTypes(Source2,{
{"Date", Int64.Type},
{"P.Code", Int64.Type},
{"SRC", Int64.Type}
}),
//Join the two tables based on PCode and Src
join = Table.NestedJoin(typeIt2,{"P.Code","SRC"},lookupTable,{"P.Code","SRC"},"Joined", JoinKind.LeftOuter),
//for each joined subtable
// Sort descending
// Select only those rows where the date in table 2 is >= the corresponding date from table 1
// Then extract the first row Rate value (as that will be the closest to the date in table 2)
#"Added Custom" = Table.AddColumn(join, "Rate1", each Table.SelectRows(Table.Sort([Joined],
{"Date",Order.Descending}),(t)=> t[Date] <= [Date])[Rate]{0}, Int64.Type),
//Remove unneeded join table column
#"Removed Columns" = Table.RemoveColumns(#"Added Custom",{"Joined"})
in
#"Removed Columns"
1 Guest(s)