Forum Discussion
unkCandyd
3 years agoFrequent Visitor
Converting SQL to DAX function lag by partition
Hello Community,
I would like to know if possible to convert this sql query to dax query.
here is the query:
SELECT * ,
Lag(User, 1,'') OVER( PARTITION BY id
ORDER BY Date ASC) AS UserTarget
FROM table
my table is:
| id | date | activity | target act | user | targetuser |
| 1 | 10-Oct | eat | drink | a | b |
| 1 | 10-Nov | drink | sleep | b | c |
| 1 | 12-Dec | sleep | xxxx | c | xxxx |
| 2 | 10-Oct | eat | dink | a | b |
| 2 | 10-Nov | drink | sleep | b | c |
| 2 | 12-Dec | sleep | xxxxx | c | xxxxx |
UserTarget = MAXX( TOPN( 1, FILTER( TBL, TBL[id] = EARLIER( TBL[id] ) && TBL[date] > EARLIER( TBL[date] ) ), TBL[date], ASC ), TBL[user] )
1 Reply
- CNENFRNLCommunity Champion
UserTarget = MAXX( TOPN( 1, FILTER( TBL, TBL[id] = EARLIER( TBL[id] ) && TBL[date] > EARLIER( TBL[date] ) ), TBL[date], ASC ), TBL[user] )