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

Calling all Data Engineers! Fabric Data Engineer (Exam DP-700) live sessions are back! Starting October 16th. Sign up.

Reply
Phuonghm22
Frequent Visitor

Count value in a column and break by a value and count again like a loop

I have a sample like this table. The column count of 2 is the output I expect. With the same ID, order Date ascending. We count number 2 (or rank) by Date. If the value in column A is 1, we break the loop and count (or rank) the number 2 again from the beginning.

Plz help me. Thank youScreenshot_1.png

1 ACCEPTED SOLUTION
v-jialluo-msft
Community Support
Community Support

Hi Phuonghm22,

 

Please follow these steps:

(1) Create a calculated column to count

 

Co2 =
VAR _date =
    CALCULATE (
        MAX ( 'Table'[Date] ),
        FILTER (
            ALL ( 'Table' ),
            'Table'[A] <> 2
                && 'Table'[Date] <= EARLIER ( 'Table'[Date] )
                && 'Table'[ID] = EARLIER ( 'Table'[ID] )
        )
    )
VAR _count =
    CALCULATE (
        COUNTROWS ( 'Table' ),
        FILTER (
            ALL ( 'Table' ),
            'Table'[Date] <= EARLIER ( 'Table'[Date] )
                && 'Table'[Date] > _date
                && 'Table'[ID] = EARLIER ( 'Table'[ID] )
        )
    ) + 0
RETURN
    _count

vjialluomsft_0-1667289690085.png

 

 

(2) Final output

vjialluomsft_0-1667289581409.png

 

 

Best Regards,

Gallen Luo

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

3 REPLIES 3
v-jialluo-msft
Community Support
Community Support

Hi Phuonghm22,

 

Please follow these steps:

(1) Create a calculated column to count

 

Co2 =
VAR _date =
    CALCULATE (
        MAX ( 'Table'[Date] ),
        FILTER (
            ALL ( 'Table' ),
            'Table'[A] <> 2
                && 'Table'[Date] <= EARLIER ( 'Table'[Date] )
                && 'Table'[ID] = EARLIER ( 'Table'[ID] )
        )
    )
VAR _count =
    CALCULATE (
        COUNTROWS ( 'Table' ),
        FILTER (
            ALL ( 'Table' ),
            'Table'[Date] <= EARLIER ( 'Table'[Date] )
                && 'Table'[Date] > _date
                && 'Table'[ID] = EARLIER ( 'Table'[ID] )
        )
    ) + 0
RETURN
    _count

vjialluomsft_0-1667289690085.png

 

 

(2) Final output

vjialluomsft_0-1667289581409.png

 

 

Best Regards,

Gallen Luo

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

Thank you so much

amitchandak
Super User
Super User

@Phuonghm22 , I think it is case of

Continuous streak : https://youtu.be/GdMcwvdwr0o

 

https://community.powerbi.com/t5/Community-Blog/Power-BI-Continuous-Streak-With-One-Day-Break/ba-p/1...

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

Helpful resources

Announcements
FabCon Global Hackathon Carousel

FabCon Global Hackathon

Join the Fabric FabCon Global Hackathon—running virtually through Nov 3. Open to all skill levels. $10,000 in prizes!

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.