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! Learn more

Reply
AlessiaN
New Member

Column counting multiple consecutive months for every ID

Hello everyone!

 

I need help finding a way (whether it's in M or DAX makes no difference) to count the number of consecutive months for:

  • Every "ID" (Text Column)
  • Having the “Status” either “Missing” or “On hold”

Here is my dummy data; the last two columns are the output I would like to see:

IDYearMonthDate (01-Month-Year)StatusConsecutive Months "Missing"Consecutive Months "On Hold"
ID402019601/06/2019Missing0-
ID402019701/07/2019Missing2-
ID402019801/08/2019Missing3-
ID4020191101/11/2019Missing0-
ID4020191201/12/2019Missing2-
ID402020901/09/2020Missing0-
ID4992019101/01/2019On Hold-0
ID4992019201/02/2019On Hold-2
ID4992019301/03/2019On Hold-3
ID4992020901/09/2020On Hold-0
ID49920201001/10/2020On Hold-2
ID4992020801/08/2020Missing0-
ID4992020901/09/2020Missing2-
ID49920201001/10/2020Missing3-
ID49920201101/11/2020Missing4-
ID49920201201/12/2020Missing5-



I followed the advice of another user and calculated the consecutive months via multiple query merge in M, but the file has become unmanageable and PowerBI is unable to load it.


Please help and thanks a lot to everyone in advance!

Alessia

1 ACCEPTED SOLUTION
Zubair_Muhammad
Community Champion
Community Champion

Hi @AlessiaN 

Try this custom column using M for consecutive missing months

=let
mymonth=[Month],
 mylist=Table.SelectRows(#"Changed Type",
(d)=>
d[Month]<=[Month] and
d[Year]=[Year] and
d[Status]=[Status] and
d[ID]=[ID]
) [Month],
merilist=List.Sort(mylist, Order.Descending),

myresult=List.Accumulate( merilist,0,(state,current)=> 
if current = mymonth-List.PositionOf(merilist,current) then (state + 1) else (state + 0) ),
interimresult=if myresult=1 then 0 else myresult
in
if [Status]="Missing" then interimresult else "-"

View solution in original post

1 REPLY 1
Zubair_Muhammad
Community Champion
Community Champion

Hi @AlessiaN 

Try this custom column using M for consecutive missing months

=let
mymonth=[Month],
 mylist=Table.SelectRows(#"Changed Type",
(d)=>
d[Month]<=[Month] and
d[Year]=[Year] and
d[Status]=[Status] and
d[ID]=[ID]
) [Month],
merilist=List.Sort(mylist, Order.Descending),

myresult=List.Accumulate( merilist,0,(state,current)=> 
if current = mymonth-List.PositionOf(merilist,current) then (state + 1) else (state + 0) ),
interimresult=if myresult=1 then 0 else myresult
in
if [Status]="Missing" then interimresult else "-"

Helpful resources

Announcements
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!

October Power BI Update Carousel

Power BI Monthly Update - October 2025

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

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.

Top Solution Authors