cancel
Showing results for 
Search instead for 
Did you mean: 
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
Microsoft
Microsoft

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 II
Super User II

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.

View solution in original post

Helpful resources

Announcements
PBI User Groups

Welcome to the User Group Public Preview

Check out new user group experience and if you are a leader please create your group

March Update

Check it Out!

Click here to read more about the March 2021 Updates!

secondImage

The largest Power BI virtual conference

100+ sessions, 100+ speakers, Product managers, MVPs, and experts. All about Power BI. Attend online or watch the recordings.

secondImage

Experience what’s next for Power BI

See the latest Power BI innovations, updates, and demos from the Microsoft Business Applications Launch Event.