Date query in Powerquery

ErsinALACA

New Member
Joined
Mar 6, 2020
Messages
31
Office Version
  1. 2019
Platform
  1. Windows
Sorry my english is not enough. I will explain it simply;

TableA;
TableA.PNG


TableB (Wanted)
TableB.PNG


Thanks for answers.
 
Dear Sandy 666;

Thank you for your kindly understanding.

I think we have signed the biggest topic in the forum's history, but as you can see in the file I linked below, the data always brings partA and values wrong. I'm not sure I did it wrong. I would be glad if you download the file on the link.

Sahin.xlsx - 201 KB
 
Upvote 0

Excel Facts

Copy a format multiple times
Select a formatted range. Double-click the Format Painter (left side of Home tab). You can paste formatting multiple times. Esc to stop
I know much bigger threads :biggrin:

ad rem
13/04/2019 taking two dates: one before and one after this date =>
DatePartPrice
13/03/2019Part A5
13/03/2019Part B6
14/06/2019Part A5.2
14/06/2019Part B6.2
18/09/2019Part A5.3
18/09/2019Part B6.3

because of dates and part where A is before B and B is after A

for 15/06/2019 is the same as above
DatePartPrice
13/03/2019Part A5
13/03/2019Part B6
14/06/2019Part A5.2
14/06/2019Part B6.2
18/09/2019Part A5.3
18/09/2019Part B6.3

the same for 17/07/2019

replace last line in the code with this line:
Type = Table.TransformColumnTypes(Table.SelectRows(Table.Sort(ExpandR,{{"Date", Order.Ascending}, {"Part", Order.Ascending}, {"Price", Order.Ascending}}), each ([Price] <> null)),{{"Date", type date},{"Price", type number}})
 
Last edited:
Upvote 0
maybe simpler will be
DatePartPriceDate
13/03/2019Part A515/06/2019
13/03/2019Part B613/04/2019
13/04/201917/07/2019
14/06/2019Part A5.2
14/06/2019Part B6.2
15/06/2019
17/07/2019
18/09/2019Part A5.3
18/09/2019Part B6.3
 
Upvote 0
my mistake , previous post should be like this
DatePartPriceDate
13/03/2019Part A515/06/2019
13/03/2019Part B613/04/2019
13/04/201917/07/2019
14/06/2019Part A5.2
14/06/2019Part B6.2
15/06/2019
17/07/2019
18/09/2019Part A5.3
18/09/2019Part B6.3
 
Upvote 0
Thank you for your effort Dear sandy666 ?. No matter how much i thank you, it will be small for your effort.

Errors encountered after revisions to your code;
DatePartPriceDateDatePartPriceDescriptions
13.03.2019Part A513.04.201913.04.2019Part A5OK, (Because date; >=13.03.2019 — <14.06.2019)
13.03.2019Part B615.06.201913.04.2019Part B6,2Must be PartB and 6
14.06.2019Part A5,217.07.201915.06.2019Part A5,2Must be 5,2 (Because date; >=14.06.2019 — <18.09.2019)
14.06.2019Part B6,220.12.201915.06.2019Part A5,3OK
18.09.2019Part A5,317.07.2019Part A5,2Value should be 5,2 (Because date; >=14.06.2019 — <18.09.2019)
18.09.2019Part B6,317.07.2019Part A5,3Value should be 6,2 (Because date; >=14.06.2019 — <18.09.2019)
20.12.2019Part B6,3OK
20.12.2019 PartA missing
 
Upvote 0
The table on the previous post is incorrect...
DatePartPriceDateDatePartPriceDescriptions
13.03.2019Part A513.04.201913.04.2019Part A5OK, (Because date; >=13.03.2019 — <14.06.2019)
13.03.2019Part B615.06.201913.04.2019Part B6,2Value should be 6
14.06.2019Part A5,217.07.201915.06.2019Part A5,2OK, (Because date; >=14.06.2019 — <18.09.2019)
14.06.2019Part B6,220.12.201915.06.2019Part A5,3Must be PartB and Value should be 6,2
18.09.2019Part A5,317.07.2019Part A5,2OK, (Because date; >=14.06.2019 — <18.09.2019)
18.09.2019Part B6,317.07.2019Part A5,3Must be PartB and Value should be 6,2
20.12.2019Part B6,3OK but 20.12.2019 PartA missing
 
Upvote 0
IndexDatePartPrice
313/04/2019Part A5first value13/04/2019 > 13/03/2019 AND 13/04/2019 < 14/06/2019 A is closer than B
313/04/2019Part B6.2second value13/04/2019 > 13/03/2019 AND 13/04/2019 < 14/06/2019 B is closer than A
615/06/2019Part A5.2first value15/06/2019 > 14/06/2019 AND 15/062019 < 18/09/2019 A is closer than B
615/06/2019Part A5.3second value15/06/2019 > 14/06/2019 AND 15/062019 < 18/09/2019 A is closer than B
717/07/2019Part A5.2and so on…
717/07/2019Part A5.3
1020/12/2019Part B6.3

it depends on sorting numbers and letters

but if you have a different proposal, I will gladly see it :geek:

:coffee::coffee::coffee::coffee::coffee:
 
Last edited:
Upvote 0
too late :)
the values are taken from the previous date and from the next date closer to lookup date and depend on sort of letters, ascending or descending

you can try this scenario where you define parts
DatePartPriceDatePart
13/03/2019Part A513/04/2019Part ?
13/03/2019Part B615/06/2019Part ?
14/06/2019Part A5.217/07/2019Part ?
14/06/2019Part B6.220/12/2019Part ?
18/09/2019Part A5.3
18/09/2019Part B6.3

but you need to write your own M-code
 
Last edited:
Upvote 0
I think I couldn't fully explain the incident due to language mismatch. Status; It is not a distance or proximity event. Consider the dates in Table 1 as follows:
date for product hikes. Even if the date written in Table2 is 1 day before the last day of the interval in Table1, the previous date (past date) will prevail.

You are tired because of me. Let's close the subject if you want. Thank you very much for your efforts and patience.
 
Upvote 0

Forum statistics

Threads
1,215,949
Messages
6,127,892
Members
449,411
Latest member
AppellatePerson

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