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
newpbiuser01
Helper IV
Helper IV

Getting the Latest Record to Merge Queries

Hello,

 

I am trying to merge two queries in Query Editor. The first query has the employee records that shows the employee status over the previous years (so we could have multiple records for the same employee if their status changes), and the second query is the sales table. I am trying to get the latest status for each employee in the sales table. How do I flag the Latest Status for each employee in the first table within Power Query and then merge the tables to only pull those records? I'd really appreciate any help! 

Employee Records Table:

DateStatus Name
09-Nov-20ActiveA
01-Nov-20InactiveA
06-Mar-20ActiveA
03-Dec-21ActiveB
12-Mar-20InactiveB
08-May-19ActiveB
09-Dec-21InactiveC
08-May-19ActiveC

 Sales Table: 

NameSalesStatus
A$1Active
B$2Active
C$1Inactive

 

Thank you!

1 ACCEPTED SOLUTION
Hariharan_R
Solution Sage
Solution Sage

Hi,

You can group the first table and get employee with latest status and then join with 2nd table to get the status easily.

 

1. Group the table by Name. Group by will generate a syntex and need to update like below.

 

 

= Table.Group(#"Changed Type", {"EmpID"}, {{"All", each  Table.AddIndexColumn(
        Table.Sort(_,{{"Date", 
        Order.Ascending}}), "Row Rank",1,1),  type table [Date=nullable date, EmpID=nullable text, Status=nullable text, Row Rank=nullable number]}})

 

Hariharan_R_0-1655441182206.png

2. Expand teh table and then filter for Rank =1

3. You can now merge with another table

 

Thanks

Hari

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.


My Blog :: YouTube Channel :: My Linkedin


View solution in original post

2 REPLIES 2
Hariharan_R
Solution Sage
Solution Sage

Hi,

You can group the first table and get employee with latest status and then join with 2nd table to get the status easily.

 

1. Group the table by Name. Group by will generate a syntex and need to update like below.

 

 

= Table.Group(#"Changed Type", {"EmpID"}, {{"All", each  Table.AddIndexColumn(
        Table.Sort(_,{{"Date", 
        Order.Ascending}}), "Row Rank",1,1),  type table [Date=nullable date, EmpID=nullable text, Status=nullable text, Row Rank=nullable number]}})

 

Hariharan_R_0-1655441182206.png

2. Expand teh table and then filter for Rank =1

3. You can now merge with another table

 

Thanks

Hari

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.


My Blog :: YouTube Channel :: My Linkedin


Thanks @Hariharan_R ! Works like a charm! 

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.