Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
peterhui50
Helper III
Helper III

Rolling Join in Power Query

I have two tables here,  A table of when individuals joined the program and when individuals have transactions. I want a conditional join by date but I don't know if it exists in Power Query.

 

Program Table

peterhui50_0-1616964288761.png

 

Transaction Table

peterhui50_1-1616964355683.png

 

 

 

Joined Table

peterhui50_2-1616964447513.png

 

The problem is this -- I joined the two tables by NAME and included a T/F column to indicate whether the transaction date is after when the individual joined the program. I just want to link it to the transactions AFTER they have joined the program. (Individuals can have multiple transactions, even before they joined the program).

 

I just want something like this - a conditional join, excluding the records that are before the Date_Joined Date.

 

peterhui50_3-1616964682844.png

 

I can't use the T and F column I had created earlier because if I filter on TRUE, it'll exlude all the folks that have transactions prior to when they have joined the program. I still need to know their names.

 

In SQL it would have been...

 

SELECT * FROM [Program Table]

LEFT JOIN [Transaction Table] ON NAME

AND [Program Table][Date Joined] <= [Transaction Table][Transactions]

 

Really hope someone out there would know this ! 

1 ACCEPTED SOLUTION

Hi @peterhui50 

 

Download sample PBIX file

 

Something like this where all Transactions are in the same field?  This keeps it at 1 record per Name, but you could also extract the data so that each Transaction is a separate record for that Name.

lst4.png

Regards

Phil



Did I answer your question? Then please mark my post as the solution.
If I helped you, click on the Thumbs Up to give Kudos.


Blog :: YouTube Channel :: Connect on Linkedin


Proud to be a Super User!


View solution in original post

7 REPLIES 7
PhilipTreacy
Super User
Super User

Hi @peterhui50 

 

Download example PBIX file

 

In your description you say that people can have multiple transactions so I added some more dummy data to my file and then created a custom column that showed either the Transaction Date if it was after they joined, null otherwsie

hui1.png

 

You can then Group on Name retaining all other columns in Tables

hui2.png

 

Then use List.Max to get the Max Date from the Custom column in each Table created above.  This will give null for transactions before the Join date

 

 

= Table.AddColumn(#"Grouped Rows", "Custom", each List.Max([All][Custom]))

 

 

hui3.png

 

Extract the Date_Joined from the Table in a similar way.

 

Delete the column with the tables, leaving you with a single row for each name, showing latest transaction date or null if their transaction was before their Date_Joined.

hui5.png

 

In my file check the Merge1 query for these steps.

 

Regards

Phil



Did I answer your question? Then please mark my post as the solution.
If I helped you, click on the Thumbs Up to give Kudos.


Blog :: YouTube Channel :: Connect on Linkedin


Proud to be a Super User!


Thanks for this Philip!

 

This will take their latest transaction, which is partly what I want but how about other transactions that fall after their join date? 

 

Sorry if I wasn't clear, but if there is a way to tweak it so that all transactions that fall after their Date_Joined it would be perfect.

 

It's like employee number 1 joined on 1/2/2019, but I also want all their transactions that fall after this date, not just the latest, so I want the 1/1/2020 and the 1/13/2020 transactions.

 

I think maybe there is a way to tweak it so that it is a a List format and it uses List.Max and any transactions that fall below it will be kept. each List.Max{All][Transactions] <= List.Min[All][Date_Joined] 

 

Hi @peterhui50 

 

Download sample PBIX file

 

Something like this where all Transactions are in the same field?  This keeps it at 1 record per Name, but you could also extract the data so that each Transaction is a separate record for that Name.

lst4.png

Regards

Phil



Did I answer your question? Then please mark my post as the solution.
If I helped you, click on the Thumbs Up to give Kudos.


Blog :: YouTube Channel :: Connect on Linkedin


Proud to be a Super User!


Thank you! I think after I can just split those up and rejig them. Ideally I was hoping that they would be in two rows.

 

It's all good, you've done a lot on this already. Thank you!

Hi @peterhui50 

No worries.

To get the transactions on separate rows, right click the TRansactions column header -> Split Column -> By Delimiter.

Choose Comma as the delimiter, and open the Advanced options, select Split into Rows

splitcol.png

 

Which gives you this

splitcol2.png

Regards

Phil



Did I answer your question? Then please mark my post as the solution.
If I helped you, click on the Thumbs Up to give Kudos.


Blog :: YouTube Channel :: Connect on Linkedin


Proud to be a Super User!


selimovd
Super User
Super User

Hey @peterhui50 ,

 

why don't you just use the SQL join as data source for Power BI?

9.png

 

There is nothing wrong with it and it seems to be a lot easier than with Power Query.

 

If you need any help please let me know.
If I answered your question I would be happy if you could mark my post as a solution ✔️ and give it a thumbs up 👍
 
Best regards
Denis
 

I would love to, but it's just not allowed. Where I work we basically work off flat csv files. That would have been a great solution.

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.