Forum Discussion
Fetching Data based on Start Date & End Date
- 2 years ago
peterpan null is reserved for Table.FillDown. So I used "none". You are free to replace it with anything else in the code but null. Or simply replace "none" with null after all transformations.
let tblB = your_table_B, tblA = Table.AddColumn(your_table_A, "Date", each [Start Date]), diff = Table.RemoveMatchingRows(tblB, Table.ToRecords(tblA), "Company"), missing = Table.FromRows( Table.ToList(diff, (x) => x & {"none"}), {"Company", "Start Date", "Rates"} ), combine = tblB & tblA & missing, sorted = Table.Sort(combine,{{"Company", Order.Ascending}, {"Date", Order.Ascending}, {"Rates", Order.Descending}}), f_down = Table.FillDown(sorted, {"Rates"}), filter = Table.SelectRows(f_down, each ([Start Date] = null)), z = Table.SelectColumns(filter, Table.ColumnNames(tblB) & {"Rates"}) in z
Thank you so much! It worked. However, if there's any other company name which is not there in TableA, it would fetch incorrect rate. Is there a way to bring null in such cases so that accuracy can be maintained?
- AlienSx2 years ago
Super User
peterpan null is reserved for Table.FillDown. So I used "none". You are free to replace it with anything else in the code but null. Or simply replace "none" with null after all transformations.
let tblB = your_table_B, tblA = Table.AddColumn(your_table_A, "Date", each [Start Date]), diff = Table.RemoveMatchingRows(tblB, Table.ToRecords(tblA), "Company"), missing = Table.FromRows( Table.ToList(diff, (x) => x & {"none"}), {"Company", "Start Date", "Rates"} ), combine = tblB & tblA & missing, sorted = Table.Sort(combine,{{"Company", Order.Ascending}, {"Date", Order.Ascending}, {"Rates", Order.Descending}}), f_down = Table.FillDown(sorted, {"Rates"}), filter = Table.SelectRows(f_down, each ([Start Date] = null)), z = Table.SelectColumns(filter, Table.ColumnNames(tblB) & {"Rates"}) in z- peterpan2 years ago
Helper I
I think this would work. Thanks. Just that we would have to keep unique values in Sr. No. at the end since we are combining missing & tableb together and filtering out start date wont remove extra row since there is no value in their for none values. Very helpful!