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

Earn the coveted Fabric Analytics Engineer certification. 100% off your exam for a limited time only!

Reply
kattlees
Post Patron
Post Patron

Keep only rows based on latest datetime value and code

I have a table that has entries like

 

AcctNum           Code             Answer      DateTime

123456               Start1            1503         3/25/19 4:27PM

123456               End1              1752         3/25/19 8:55PM

123456               Start1             1510         3/25/19  5:15PM

 

I want to keep the row for each code/acctnum with the last datetime entry

In the above example it would only keep the last two rows. 

1 ACCEPTED SOLUTION

I was able to get what I need creating a new table and then pulling the latest answer for each field name. I couldn't get anything else to work. I appreciate all the help tho. So many great ideas I will be using for other things.

View solution in original post

6 REPLIES 6
v-danhe-msft
Employee
Employee

Hi @kattlees ,

Based on my test, you could refer to below steps:

Add index for your data in query editor:

1.PNG

Apply it and use the Top N filter for your data table:

2.PNG

Regards,

Daniel He

Community Support Team _ Daniel He
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Thanks for this, but I need to do it in the power query because I then pivot the table so each code has it's own column with just the latest value. 

Hi @kattlees ,

You could refer to below link to use Keep rows function:

https://community.powerbi.com/t5/Desktop/Top-N-query-with-direct-query/td-p/236401

 

Regards,

Daniel He

Community Support Team _ Daniel He
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
TomMartens
Super User
Super User

Hey,

 

can you please explain the rule.why you just want to keep the last two rows?

 

Regards,

Tom



Did I answer your question? Mark my post as a solution, this will help others!

Proud to be a Super User!
I accept Kudos 😉
Hamburg, Germany

Our system saves a row each time a new entry is added for each code. So on one form, there could be 5 entries for the same code and account. The only one I care about is the last one entered.

I was able to get what I need creating a new table and then pulling the latest answer for each field name. I couldn't get anything else to work. I appreciate all the help tho. So many great ideas I will be using for other things.

Helpful resources

Announcements
April AMA free

Microsoft Fabric AMA Livestream

Join us Tuesday, April 09, 9:00 – 10:00 AM PST for a live, expert-led Q&A session on all things Microsoft Fabric!

March Fabric Community Update

Fabric Community Update - March 2024

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