Search code examples
filterpowerbimaxdaxlookup

Looking up a specific value from a table


I have the below function that works, but what I'm not sure how to do is within the devices table there is a [CreatedBy] column. I want to pull the [UserDeviceType] for the most recent [CreatedBy] row by [user]

How could I modify the below to do this?

UserDeviceType = 
    CALCULATE(
        MAX('devices'[UserDeviceType]),
        FILTER(
            'devices',
            'devices'[user] = 'users'[_id]
        )
    )

Solution

  • For calculated column, the following formula works:

    UserDeviceType = 
    VAR _user = [_id]
    VAR _tbl = FILTER(devices, [user] = _user)
    VAR _latest = MAXX(_tbl, [CreatedBy])
    RETURN MAXX(FILTER(_tbl, [CreatedBy] = _latest), [UserDeviceType])
    

    enter image description here

    devices table:
    enter image description here