Forum Discussion
Power query transformations to lookup dates from one table into the other
- 2 years ago
You can do that.
For instance, if you wanted to add your EM - Misc Charge table (with dates) to the Invoice Detail table you could add this step to the Invoice Detail query.
combineTables = Table.Combine( { #"Changed Type", Table.ExpandTableColumn( Table.NestedJoin( #"EM - Misc Charge", {"DBName-Point_Id", "DBName-Id", "Charge"}, #"Changed Type", {"DBName-Point_Id", "DBName-Id", "Charge"}, "Invoice Detail", JoinKind.LeftOuter ), "Invoice Detail", {"Date"}, {"Date"} ) } )Again I note that this only works correctly if you have an unique key to build the join with.
In the dummy set for an example if you look atThere are four rows that are not unique. So they end up joining with 245 rows in the Invoice Detail table that are 'EMSQL_BWS-33524, EMSQL_BWS-159176, Standing_Charge'.
Hope this gets you pointed in the right direction.
Cheers.
In theory you can merge the Invoice Detail table into the EM - Misc Charge table using the three common columns as the link. (Ctrl + click to select multiple columns.)
It appears though in your data that the EMSQL_BWS lines in EM - Misc Charge table have multiple same entries so you will get a list of dates for each of those rows instead of a single value. In your data set provided this increases the row count of the EM - Misc Charge table from 109 to 418.
Hope this gets you pointed in the right direction.
Hi jgeddes ,
Thanks for your response! This is a dummy data set that i have provided which i described earlier.
So your solution will cause performance issues as there will be millions of rows after the merge in my original data set.(not this dummy 418)
Is there any other m-function that we can use to find the dates for rows?
Or any other solution without merging the tables to get the dates?
Thanks in advance!
- jgeddes2 years ago
Super User
No problem, I understand your concern.
For comparison sake I also ran a function in an add column step (code below)
Table.AddColumn(#"Changed Type", "addedColumn", (x)=> Table.SelectRows(#"Invoice Detail", each [#"DBName-Point_Id"] = x[#"DBName-Point_Id"] and [#"DBName-Id"] = x[#"DBName-Id"] and [Charge] = x[Charge]))The merge queries version took 0.00:00:00.010246.
The add column function took 0.00:00:00.013154.
Merge queries version was slightly faster on the dummy set.
Hopefully one of the PQ gurus can optimize this further for you.
- sivarajan212 years ago
Post Prodigy
Hi jgeddes
Thanks for your quick response!
Thats brilliant that you gave a comparison of timing between two.
Let me have a look and then get back!
Meanwhile lets see for other Power queries experts to have a look into this.
Thanks in advance!
- sivarajan212 years ago
Post Prodigy
Hi jgeddes ,
Just to confirm, how did you calculate the timing of the queries that you mentioned above?
Could you please help me with that?
Thanks in advance!
- jgeddes2 years ago
Super User
In the tool ribbon I selected Diagnose Step.
In the last of generated diagnostic queries the total dutation is noted...