Forum Discussion

KayceVC's avatar
KayceVC
Helper II
7 years ago
Solved

Find Value in Same Table

I have an audit table which contains audit log data. I am trying to isolate when a particular event happens, if another event happens on the same day for the same user. 

 

 

In this example, I would be looking for when Key_ID 22 happens, is it followed by a 41 on the same date by the same user. I tried using a LOOKUPVALUE function nested in an IF, but since I did not know if or where the record could occur, I could not figure out what value to input for the search value parameter.  I do have 2 multiple index on the table, one for all the table records and one for parent records that shows what order the child records happened in. 

 

What I am looking for at a minimum is to return the date the 41 event happened on or a 1 if there is no 41. In a perfect world, I would have the column returning a 0 for instances where the 41 followed the 22 on the same day by the same user and a 1 when this condition is not met. 

 

Any help to get me moving on this would be appreciated. 

  • Hello KayceVC 

    Give this a try.  I had a check for the time on the 42 being after the time on the row but it doesn't read like you need that but I left it in the code and just commented it out.

    Result = 
    VAR TheDate = DATEVALUE ( auditdata[Date_Updated] )
    VAR TheDateTime = auditdata[Date_Updated]
    VAR TheUser = auditdata[User]
    VAR NumRows = 0
    RETURN
        IF (
            auditdata[Key_ID] = 22,
            CALCULATE (
                MAX ( auditdata[Date_Updated] ),
                FILTER (
                    auditdata,
                    auditdata[User] = TheUser
                    && auditdata[Key_ID] = 41
                    && DATEVALUE ( auditdata[Date_Updated] ) = TheDate
                    --&& auditdata[Date_Updated] > TheDateTime
                )
            )
        )

5 Replies

  • Hello KayceVC ,

    Can you add the result column to your screen shot for what you would like to see?

    ParentIDChildIDKey_IDUserDate_UpdatedTableIndexRecordIndexResult
    4061223221Aguy6/27/2019151 
    4061223322Aguy6/27/2019162 
    406122342Aguy6/27/2019173 
    4061223522Aguy6/27/2019184 
    406122363Aguy6/27/2019195 
    4061223741Aguy6/27/2019206 
    406122381Agirl6/27/2019217 
    406122393Agirl6/27/2019228 
    406122401Agirl6/27/2019239 
    • KayceVC's avatar
      KayceVC
      Helper II

      Hey jdbuchanan71 

      This would be what I would expect. I would like to return the date where the 41 on the same day occurred on the row item for the associated 22. This will allow me to calculate the 2 follow up values I need a boolean for was the 41 record (a time entry note) updated within the allowed time (before the end of the day) and then a calculation for how long it took for each 22 record to receive the time entry update. 

       

      ParentIDChildIDKey_IDUserDate_UpdatedTableIndexRecordIndexResult 
      4061223221Aguy6/27/19 1:00151 
      4061223322Aguy6/27/19 2:001626/27/19 2:45
      406122342Aguy6/27/19 2:15173 
      4061223522Aguy6/27/19 2:301846/27/19 2:45
      406122363Aguy6/27/19 2:30195 
      4061223741Aguy6/27/19 2:45206 
      406122381Agirl6/27/19 3:05217 
      406122393Agirl6/27/19 3:15228 
      406122401Agirl6/27/19 4:00239 

       

      PattemManohar Unfortunately this is as much sample data as I can provide. It is formatted exactly how my real data is, but due to the senstive nature of my data, I am not permitted to post actual system data. The above sample is very close to my ideal input/output though.


       

      • jdbuchanan71's avatar
        jdbuchanan71
        Super User

        Hello KayceVC 

        Give this a try.  I had a check for the time on the 42 being after the time on the row but it doesn't read like you need that but I left it in the code and just commented it out.

        Result = 
        VAR TheDate = DATEVALUE ( auditdata[Date_Updated] )
        VAR TheDateTime = auditdata[Date_Updated]
        VAR TheUser = auditdata[User]
        VAR NumRows = 0
        RETURN
            IF (
                auditdata[Key_ID] = 22,
                CALCULATE (
                    MAX ( auditdata[Date_Updated] ),
                    FILTER (
                        auditdata,
                        auditdata[User] = TheUser
                        && auditdata[Key_ID] = 41
                        && DATEVALUE ( auditdata[Date_Updated] ) = TheDate
                        --&& auditdata[Date_Updated] > TheDateTime
                    )
                )
            )

  • PattemManohar's avatar
    PattemManohar
    Community Champion

    KayceVC  Could you please post the sample data that can be copied instead of screenshot. Also, what is your expected output... Please post the expected output as well.

    Is it just to list ParentIDs and Flag (if there is a Key_ID 22 and followed by 41 for same user on same day)