Forum Discussion

shubham-sharma's avatar
shubham-sharma
Frequent Visitor
5 years ago
Solved

Get the second last value for same id's coming in multiple rows

Hi, I need help to fetch 2nd last date and status from the table but the table consists of multiple rows of the same IDs. So if there 3 same IDs its last status is EXPIRED but the 2nd last status can...
  • v-robertq-msft's avatar
    5 years ago

    Hi, shubham-sharma 

    According to your description, I can roughly understand your requirement, I created some test data and achieved your requirement, I think you can try my steps:

    This is my test data:

     

    1. I created two calculated columns in the main table:
    Appear times = RANKX(FILTER(ALL('Table'),[_id]=EARLIER('Table'[_id])),[activityLog.loggedAt],,ASC,Dense)
    Total appear times = COUNTX(FILTER(ALL('Table'),[_id]=EARLIER('Table'[_id])),[activityLog.loggedAt])
    1. I created a calculated table like this:
    Expected output =
    
    SELECTCOLUMNS(FILTER('Table',[Appear times]=[Total appear times]-1),"ID",[_id],"Date",[activityLog.loggedAt],"Status",[activityLog.status])

     

    And you can get what you want, like this:

     

    You can download my test pbix file below

     

    If this result is not what you want, you can post some sample data(without sensitive data) and your expected result.

    How to Get Your Question Answered Quickly 

    Thank you very much!

     

    Best Regards,

    Community Support Team _Robert Qin

    If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.