Advance your Data & AI career with 50 days of live learning, dataviz contests, hands-on challenges, study groups & certifications and more!
Get registeredGet Fabric Certified for FREE during Fabric Data Days. Don't miss your chance! Learn more
i have table like below and requirement is,
need to calculate the CategoryID for each Id whose ActiveFlag =1 and latest statflag is 0 and old statflag is 1
| ID | CategoryID | Activeflag | statflag | calenderDate | Count | 
| a123 | 1 | 1 | 0 | 4/14/2021 | 1 | 
| a123 | 2 | 1 | 1 | 4/14/2021 | 0 | 
| a123 | 3 | 1 | 1 | 4/14/2021 | 0 | 
| a123 | 4 | 1 | 1 | 4/14/2021 | 0 | 
| b233 | 1 | 1 | 0 | 1/1/2021 | 0 | 
| b233 | 2 | 1 | 0 | 1/1/2021 | 1 | 
| b233 | 3 | 1 | 1 | 1/1/2021 | 0 | 
| c233 | 1 | 1 | 1 | 1/1/2021 | 0 | 
| e343 | 2 | 1 | 1 | 2/6/2021 | 0 | 
| f234 | 2 | 1 | 0 | 2/6/2021 | 0 | 
| a123 | 1 | 1 | 1 | 2/6/2021 | 0 | 
| b233 | 2 | 1 | 1 | 2/6/2021 | 0 | 
Solved! Go to Solution.
@Naresh91 , Try new column like
New column = 
var _date = sumx(filter(Table, [ID] = earlier([ID]) && [CategoryID] =earlier([CategoryID]) && [calenderDate] <earlier([calenderDate])),[calenderDate])
var _statflag = sumx(filter(Table, [ID] = earlier([ID]) && [CategoryID] =earlier([CategoryID]) && [calenderDate] =_date),[statflag])
return 
if([statflag] =0 && _statflag= 1, 1,0)
Hi @amitchandak ,
from the above data "a123" have statflag =1 for CategoryID 1 on "2/6/2021"
and "a123" have statflag =0 for CategoryID 1 on "4/14/2021"
 so it will consider as Lost ID and so count will be 1 
similar way for "b233" have statflag =1 for CategoryID 2 on "2/6/2021"
and "b233" have statflag =0 for CategoryID 2 on "1/1/2021"
so here also count is 1
so like this for the above data Lost count will be 2 as "a123" and "b233" lost their one CatogeryId
@Naresh91 , Try new column like
New column = 
var _date = sumx(filter(Table, [ID] = earlier([ID]) && [CategoryID] =earlier([CategoryID]) && [calenderDate] <earlier([calenderDate])),[calenderDate])
var _statflag = sumx(filter(Table, [ID] = earlier([ID]) && [CategoryID] =earlier([CategoryID]) && [calenderDate] =_date),[statflag])
return 
if([statflag] =0 && _statflag= 1, 1,0)
Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!
Check out the October 2025 Power BI update to learn about new features.
            | User | Count | 
|---|---|
| 8 | |
| 5 | |
| 5 | |
| 4 | |
| 3 | 
| User | Count | 
|---|---|
| 24 | |
| 11 | |
| 10 | |
| 9 | |
| 8 |