Forum Discussion

pedanticpad's avatar
pedanticpad
Helper II
6 years ago
Solved

Assign Department from Audit Table

Hi,   I have employee data from a time management system with clock in and out per day laid out in a table like the below; DATE USERID CLOCK 25/02/2020 1234 08:00:00 25/02/2020 1234 ...
  • v-alq-msft's avatar
    v-alq-msft
    6 years ago

    Hi, pedanticpad 

     

    Based on your data, you may create two calculated columns in 'Clock' table as follows.

     

    COSTCODE = 
    CALCULATE (
        MAX ( 'Audit'[NewValue] ),
        FILTER (
            'Audit',
            'Audit'[UserID] = 'Clock'[UserID]
                && 'Audit'[ChangeType] = "COSTCODE"
                && 'Audit'[ChangeDate]
                    = CALCULATE (
                        MAX ( 'Audit'[ChangeDate] ),
                        FILTER (
                            'Audit',
                            'Audit'[ChangeDate] <= 'Clock'[Date]
                                && 'Audit'[UserID] = 'Clock'[UserID]
                        )
                    )
        )
    )
    
    DEPARTMENT = 
    CALCULATE (
        MAX ( 'Audit'[NewValue] ),
        FILTER (
            'Audit',
            'Audit'[UserID] = 'Clock'[UserID]
                && 'Audit'[ChangeType] = "DEPARTMENT"
                && 'Audit'[ChangeDate]
                    = CALCULATE (
                        MAX ( 'Audit'[ChangeDate] ),
                        FILTER (
                            'Audit',
                            'Audit'[ChangeDate] <= 'Clock'[Date]
                                && 'Audit'[UserID] = 'Clock'[UserID]
                        )
                    )
        )
    )

     

     

    Result:

     

    Best Regards

    Allan

     

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