Count new device

Hi. I am trying to count new device_id in a given timeframe that does not exist before.
E.g. If the time frame is week, then the device_id shown in that week must not exist before that week.

In sql, it would be something like:

SELECT device_id FROM TableName T1
WHERE NOT EXIST (
    SELECT 1 FROM TableName T2 WHERE T1.device_id = T2.device_id
    AND {before this week}
) AND {this week}

How can I achieve such result with LookML code?

I have the following 2 dimensions:

 dimension_group: timestamp {
    type: time
    sql: ${TABLE}.TIMESTAMP ;;
  }

 dimension: device_id {
    type: string
    sql: ${TABLE}.DEVICE_ID ;;
  }

How can I link device_id to the timestamp dimension so that only device_id in that timestamp and not exist before that timestamp would appear? Any help would be greatly appreciated! Thank you.