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
KayceVC
Helper II
Helper II

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. 

 

SameTableRecord.JPG

 

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. 

1 ACCEPTED SOLUTION

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
            )
        )
    )

auditdata.jpg

View solution in original post

5 REPLIES 5
PattemManohar
Community Champion
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)





Did I answer your question? Mark my post as a solution!

Proud to be a PBI Community Champion




jdbuchanan71
Super User
Super User

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 

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.


 

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
            )
        )
    )

auditdata.jpg

Sorry for getting back to this so late, my project priority got reassigned. 

 

Your solution worked brilliantly and very quickly. I was afraid with all the steps it might be a long running column, but it updated in less than 5s. This was exactly what I needed, thank you so much!

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.