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

July 7 - July 17 | Round 2 of the Power BI Dataviz World Championships. Don't miss your chance! Learn more

Reply
PowerBITestingG
Resolver I
Resolver I

Count Consecutive Increasing Amounts

I have the following table. I need a calculated column that returns the count of consecutive LotNumber that has an increasing Amount. I have browsed similar solution but I cant get one to work on my table without crashing the pbix file

 

ItemLotNumberAmountIncreasingConsecutiveCount
Table1101
Table3202
Table5303
Table9201
Table11101
Table13.6202
Table16.2903
Table18.8101
Table21.4112
Table24123
Table25134
Table26145
1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi @PowerBITestingG 

You can try the following modified calculated columns

Rank =
RANKX (
    FILTER ( 'Table', [Item] = EARLIER ( 'Table'[Item] ) ),
    [LotNumber],
    ,
    ASC
)
Flag =
VAR a =
    CALCULATE (
        SUM ( 'Table'[Amount] ),
        ALLEXCEPT ( 'Table', 'Table'[Item] ),
        'Table'[Rank]
            = EARLIER ( 'Table'[Rank] ) - 1
    )
RETURN
    IF ( [Amount] > a, 1, 0 )
ConsecutiveCount =
VAR a =
    MAXX (
        FILTER (
            'Table',
            [Flag] = 0
                && [Item] = EARLIER ( 'Table'[Item] )
                && [Rank] <= EARLIER ( 'Table'[Rank] )
        ),
        [Rank]
    )
RETURN
    SWITCH ( TRUE (), a = BLANK (), [Rank], [Rank] = a, 1, [Rank] - a + 1 )

Output

vxinruzhumsft_0-1716945799497.png

 

Best Regards!

Yolo Zhu

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

 

View solution in original post

5 REPLIES 5
ThxAlot
Super User
Super User

ThxAlot_0-1716466633090.png



Expertise = List.Accumulate(


        {Days as from Today},


        {Skills and Knowledge},


        (Current, Everyday) => Current & Day.LearnAndPractise(Everyday)


)



Thank you for that. Would you know why when you add another column everything turns to 1?

Anonymous
Not applicable

Hi,

Thanks for the solution @ThxAlot provided, it is excellent, and i want to offer some more information for user to refer to.

hello @PowerBITestingG , based on your descriotion, you can create the following calcualted columns.

Rank = RANKX('Table',[LotNumber],,ASC)
Flag =
VAR a =
    LOOKUPVALUE ( 'Table'[Amount], [Rank], [Rank] - 1 )
RETURN
    IF ( [Amount] > a, 1, 0 )
ConsecutiveCount =
VAR a =
    MAXX (
        FILTER ( 'Table', [Flag] = 0 && [Rank] <= EARLIER ( 'Table'[Rank] ) ),
        [Rank]
    )
RETURN
    SWITCH ( TRUE (), a = BLANK (), [Rank], [Rank] = a, 1, [Rank] - a + 1 )

Output

vxinruzhumsft_0-1716791590647.png

 

Best Regards!

Yolo Zhu

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

The issue now is that if you use the entire dummy data I shared (with Item Chair), the code stops working 

Anonymous
Not applicable

Hi @PowerBITestingG 

You can try the following modified calculated columns

Rank =
RANKX (
    FILTER ( 'Table', [Item] = EARLIER ( 'Table'[Item] ) ),
    [LotNumber],
    ,
    ASC
)
Flag =
VAR a =
    CALCULATE (
        SUM ( 'Table'[Amount] ),
        ALLEXCEPT ( 'Table', 'Table'[Item] ),
        'Table'[Rank]
            = EARLIER ( 'Table'[Rank] ) - 1
    )
RETURN
    IF ( [Amount] > a, 1, 0 )
ConsecutiveCount =
VAR a =
    MAXX (
        FILTER (
            'Table',
            [Flag] = 0
                && [Item] = EARLIER ( 'Table'[Item] )
                && [Rank] <= EARLIER ( 'Table'[Rank] )
        ),
        [Rank]
    )
RETURN
    SWITCH ( TRUE (), a = BLANK (), [Rank], [Rank] = a, 1, [Rank] - a + 1 )

Output

vxinruzhumsft_0-1716945799497.png

 

Best Regards!

Yolo Zhu

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

 

Helpful resources

Announcements
FabCon and SQLCon Barcelona 2026

FabCon & SQLCon – Barcelona 2026

Join us in Barcelona for FabCon and SQLCon, the Fabric, Power BI, SQL, and AI community event. Save €200 with code FABCMTY200.

60 days of Data Days Carousel

Data Days 2026

Join Data Days 2026: 60 days of free live/on-demand sessions, challenges, study groups, and certification opportunities.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.

Top Solution Authors