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.
 

Excel Facts

Format cells as time
Select range and press Ctrl+Shift+2 to format cells as time. (Shift 2 is the @ sign).
here is
DatePartPriceDateDatePartPrice
02/03/2020Part1320/03/202001/03/2020Part13
02/03/2020Part2528/03/202020/03/2020Part49
05/03/2020Part3701/03/202020/03/2020Part511
09/03/2020Part4928/03/2020Part613
25/03/2020Part51128/03/2020Part719
25/03/2020Part613
31/03/2020Part719
 
Upvote 0
extended version
Table1Table2Result
DatePartPriceDateDatePartPriceout of range
02/03/2020Part1320/03/202025/02/2020Part13exact match
02/03/2020Part2528/03/202005/03/2020Part37restapprox. match
05/03/2020Part3725/02/202005/03/2020Part823
09/03/2020Part41111/04/202020/03/2020Part411
25/03/2020Part51305/03/202020/03/2020Part513
25/03/2020Part61728/03/2020Part617
31/03/2020Part71928/03/2020Part719
05/03/2020Part82311/04/2020Part719

if date(s) from Table2 exist in Table1 then result will be this date and data - Exact Match
if date(s) from Table2 doesn't exist in Table1 then result will be first and last date and data from the range of Table1 - Approx. Match
if date(s) from Table2 doesn't exist in Table1 but exist in range of dates in Table1 then result will be the first date before/after the date from Table2 - Approx. Match
 
Upvote 0
Yes, exactly as I wanted, Thank you sandy 666. I can't see the codes, where?
 
Upvote 0
I was hoping to see your code first ? :ROFLMAO:

I'm not a master, I'm very new at Powerquery. I can add new columns and do things with built-in functions, but I can't write code. I keep getting errors all the time. I am having trouble implementing the functions I display with "= # Shared". "I can't turn into a table" error every time is really annoying
 
Upvote 0
ok,
Code:
// Query1
let
    Tbl1 = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
    Tbl2 = Excel.CurrentWorkbook(){[Name="Table2"]}[Content],
    Base = Table.ExpandTableColumn(Table.NestedJoin(Tbl2,{"Date"},Tbl1,{"Date"},"Tbl1",JoinKind.FullOuter), "Tbl1", {"Date", "Part", "Price"}, {"Date.1", "Part", "Price"}),
    Conditions = Table.AddColumn(Base, "Custom", each if [Date] = null then [Date.1] else [Date]),
    FillU = Table.FillUp(Table.SelectColumns(Table.Sort(Conditions,{{"Custom", Order.Ascending}}),{"Custom", "Part", "Price"}),{"Part", "Price"}),
    FillD = Table.FillDown(Table.SelectColumns(Table.Sort(Conditions,{{"Custom", Order.Ascending}}),{"Custom", "Part", "Price"}),{"Part", "Price"}),
    Mrg = Table.NestedJoin(Tbl2,{"Date"},Table.Combine({FillU, FillD}),{"Custom"},"Ap",JoinKind.LeftOuter),
    ExpandR = Table.Distinct(Table.ExpandTableColumn(Mrg, "Ap", {"Part", "Price"}, {"Part", "Price"})),
    Type = Table.TransformColumnTypes(Table.SelectRows(Table.Sort(ExpandR,{{"Date", Order.Ascending}, {"Part", Order.Ascending}, {"Price", Order.Ascending}}), each ([Price] <> null)),{{"Date", type date}})
in
    Type
but you have to figure out how it was done by yourself :cool:
note: dates and data can be in random order in both source tables
 
Upvote 0
but you have to figure out how it was done by yourself :cool:
I can easily do anything I want to do in VBA. Unfortunately I can't show 10% of the same success in Powerquery. Annoying error messages, case sensitivity. What attracted me is the easy data formatting feature. It can format data in SAP systems easily and quickly. Especially in date type data. In Excel, you need to write a formula like MID etc.

Thank you for codes ?
 
Upvote 0

Forum statistics

Threads
1,223,798
Messages
6,174,667
Members
452,576
Latest member
AlexG_UK

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