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
greta
Frequent Visitor

List.Accumulate or what?

Dear All, thank you for your time. 
I have a request that seems really complicated to me, I don't know if it's achievable. I've recreeated the data I'm working with in a simplified table that I'm posting here below.

greta_0-1700568550417.png

As you can see, I have different projects that at different dates ("mese" column), have different status. 
The request is to calculate the number of months in which the project consecutively stays in "on hold", starting from the most recent. So for proj4 the result would be 2, for prog2, 1 and for prog1, 2.
I have tried in desktop with a measure,

OnHold_ =
var max_data = calculate(max(mese), removefilters(table))
var min_data = calculate(max(PjDev_HistoricalData[UpdatePP&CC]meseData[UpdatePP&CC]))
var _result = averagex(table, datediff(min_data, max_data, month))
return _result

but it oesn't display a cumulated value.
Any hint on how I could achieve this result?
Many thanks in advance
2 ACCEPTED SOLUTIONS
AlienSx
Super User
Super User

Hello, @greta 

let
    Source = simplified_table,
    z = Table.Group(
        Source, {"prog"}, 
        {{
            "on_hold", 
            each List.PositionOf(
                Table.Sort(_, {"index", Order.Descending})[status],
                "on hold", 
                Occurrence.First, 
                (x, y) => x <> y
            )
        }}
    )
in
    z

View solution in original post

@greta I did not consider the case when all values are On Hold. Try this instead:

let
    Source = Lista_OnHold,
    z = Table.Group(
        Source, {"MercatusCode"},
        {{
            "On_Hold",
            each 
                [lst = Table.Sort(_, {"Index.1", Order.Descending})[ProjectStatusInternal.1],
                pozz = List.PositionOf(lst, "On Hold", Occurrence.First, (x, y) => x <> y),
                zz = if pozz = -1 then List.Count(lst) else pozz][zz]
        }}
    )
in
    z

View solution in original post

7 REPLIES 7
wdx223_Daniel
Super User
Super User

Measure=CALCUATE(IF(MAXX(TOPN(1,Table,Table[index],DESC),Table[Status])="on hold",MAX(Table[index])-LASTNONBLANK(VALUES(Table[index]),IF(CALCULATE(MAX(Table[Status])="on hold",1))),ALLEXCPT(Table,Table[Project]))

Thank you very much for your support!

AlienSx
Super User
Super User

Hello, @greta 

let
    Source = simplified_table,
    z = Table.Group(
        Source, {"prog"}, 
        {{
            "on_hold", 
            each List.PositionOf(
                Table.Sort(_, {"index", Order.Descending})[status],
                "on hold", 
                Occurrence.First, 
                (x, y) => x <> y
            )
        }}
    )
in
    z
greta
Frequent Visitor

I've adapted the query to the following dataset,

greta_0-1700832305441.png

As follows:

let
    Source = Lista_OnHold,
    z = Table.Group(
        Source, {"MercatusCode"},
        {{
            "On_Hold",
            each List.PositionOf(
                Table.Sort(_, {"Index.1", Order.Descending})[ProjectStatusInternal.1],
                "On Hold",
                Occurrence.First,
                (x, y) => x <> y
            )
        }}
    )
in
    z
And I'm getting this result
greta_1-1700832361326.png

Could you help me in understanding why?
Many thanks in advance

@greta I did not consider the case when all values are On Hold. Try this instead:

let
    Source = Lista_OnHold,
    z = Table.Group(
        Source, {"MercatusCode"},
        {{
            "On_Hold",
            each 
                [lst = Table.Sort(_, {"Index.1", Order.Descending})[ProjectStatusInternal.1],
                pozz = List.PositionOf(lst, "On Hold", Occurrence.First, (x, y) => x <> y),
                zz = if pozz = -1 then List.Count(lst) else pozz][zz]
        }}
    )
in
    z
greta
Frequent Visitor

Works perfectly, many thanks!

greta
Frequent Visitor

Many thanks, that's exactly what I needed!

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.