Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Get Fabric Certified for FREE during Fabric Data Days. Don't miss your chance! Request now

Reply
StacyJEH
Frequent Visitor

How do I work out which ID numbers are new, or repeats in a list each month

I have the below data which shows which 'Person IDs' appear each month, I need to be able to replicate the last column in the table  - 'Frequency'.

'Frequency' needs to show if a 'Person ID' number is appearing for the first time ('New'), or was present the previous month ('Repeat') or if there has been a gap of one or more months that there have re-appeared but are not new ('Re-entry').

I can calculate the 'New' element by simply doing the duration between 'Involved Date' and 'First Date', if the result is zero labelling it as 'New' but the 'Repeat' and 'Re-entry' has me stumped?

Any help or suggestions would be welcomed.

 

Person IDInvolved DateFirst dateDays between Involved and FirstFrequency (Expected results)
100101/01/202401/01/20240New
100101/03/202401/01/202460Re-entry
100101/04/202401/01/202491Repeat
100101/06/202401/01/2024152Re-entry
100201/02/202401/02/20240New
100201/04/202401/02/202460Re-entry
100201/05/202401/02/202490Repeat
100301/03/202401/03/20240New
100301/04/202401/03/202431Repeat
100401/04/202401/04/20240New
100501/01/202401/01/20240New
100501/03/202401/01/202460Re-entry
100501/05/202401/01/2024121Repeat
100601/02/202401/02/20240New
100601/05/202401/02/202490Re-entry
100701/02/202401/02/20240New
100801/01/202401/01/20240New
100801/02/202401/01/202431Repeat
100901/02/202401/02/20240New
101001/01/202401/01/20240New
101001/03/202401/01/202460Re-entry
101001/06/202402/01/2024151Re-entry
1 ACCEPTED SOLUTION
AlienSx
Super User
Super User

let
    Source = your_table,
    fx = (tbl) => 
        [recs = Table.ToRecords(Table.Sort(tbl, "Involved Date")),
        gen = List.Generate(
            () => [i = 0, r = recs{0}, result = "New"],
            (x) => x[i] < List.Count(recs),
            (x) => 
                [
                    i = x[i] + 1, 
                    r = recs{i}, 
                    result = 
                        if Date.AddMonths(x[r][Involved Date], 1) = r[Involved Date]
                        then "Repeat"
                        else "Re-entry"
                ],
            (x) => x[r] & [result = x[result]]
        )][gen],
    group = Table.Group(
        Source, "Person ID",
        {"x", fx}
    ),
    result = Table.FromRecords(List.Combine(group[x]))
in
    result

View solution in original post

3 REPLIES 3
AlienSx
Super User
Super User

let
    Source = your_table,
    fx = (tbl) => 
        [recs = Table.ToRecords(Table.Sort(tbl, "Involved Date")),
        gen = List.Generate(
            () => [i = 0, r = recs{0}, result = "New"],
            (x) => x[i] < List.Count(recs),
            (x) => 
                [
                    i = x[i] + 1, 
                    r = recs{i}, 
                    result = 
                        if Date.AddMonths(x[r][Involved Date], 1) = r[Involved Date]
                        then "Repeat"
                        else "Re-entry"
                ],
            (x) => x[r] & [result = x[result]]
        )][gen],
    group = Table.Group(
        Source, "Person ID",
        {"x", fx}
    ),
    result = Table.FromRecords(List.Combine(group[x]))
in
    result

This works perfectly!!!!! Thank you so much.

 

This solution is being used in a report that will identify and allow protectection for vulnerable children so you've not only helped me but potentially you've helped thousands!! 

ManuelBolz
Responsive Resident
Responsive Resident

Hello @StacyJEH,

try the folowing Steps

1. You need a Copy of that query.
2. Name thay query "FrequencyLastInvolved"
3. Order FrequencyLastInvolved by [Involved Date] descending

4. Then use the function Table.Buffer()

5. Remove Dublicates on [Person ID]
6. Go to your first query "Frequency"
7. Leftjoin "FrequencyLastInvolved[Person ID]" to "Frequency[Person ID]"
8. Expand/Rename [Involved Date Last] from FrequencyLastInvolved
9. Now you have for each Row the latest [Involved Date] and you can your logic. 
if  [Involved Date Last] - [Involved Date Last] = 0 then "New"
else if  [Involved Date Last] - [Involved Date Last] >= 31 then "Re-entry"
else "Repeat"

Helpful resources

Announcements
November Power BI Update Carousel

Power BI Monthly Update - November 2025

Check out the November 2025 Power BI update to learn about new features.

Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.