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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
xrieraca
Frequent Visitor

Count consecutive days between months

Hi Im pretty new to Power BI and I can't think how to do a measure to calculate this.

 

I want to calculate if someone has assist 3 to 5 days in a row, an if its true, count 1 asisstance in the month of the latest day.

 

I have this table:

Person day Assist
A28/01/221
A29/01/221
A30/01/221
A31/01/221
A01/02/221
B02/02/221
B03/02/220
B04/02/221
C05/02/221
C06/02/221
C07/02/221

 

I want a result table like this:

Person Month Assistance
AFebruary1
CFebruary1

 

Any help would be very appreciate.

 

Many thanks.

1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi @xrieraca ,

 

You can create two measures to get it.

Assistance =
VAR _sum =
    CALCULATE (
        SUM ( 'Table'[Assist] ),
        FILTER ( ALLSELECTED ( 'Table' ), [Person] = MAX ( 'Table'[Person] ) )
    )
VAR _count =
    CALCULATE (
        COUNT ( 'Table'[Assist] ),
        FILTER ( ALLSELECTED ( 'Table' ), [Person] = MAX ( 'Table'[Person] ) )
    )
RETURN
    IF ( _count = _sum, 1 )
Month =
FORMAT (
    MAXX (
        FILTER ( ALLSELECTED ( 'Table' ), [Person] = MAX ( 'Table'[Person] ) ),
        [day]
    ),
    "mmmm"
)

Note:set the Assistance measure show items when the value is 1.

vstephenmsft_0-1646122164303.png

 

 

 

Best Regards,

Stephen Tao

 

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

4 REPLIES 4
Anonymous
Not applicable

Hi @xrieraca ,

 

You can create two measures to get it.

Assistance =
VAR _sum =
    CALCULATE (
        SUM ( 'Table'[Assist] ),
        FILTER ( ALLSELECTED ( 'Table' ), [Person] = MAX ( 'Table'[Person] ) )
    )
VAR _count =
    CALCULATE (
        COUNT ( 'Table'[Assist] ),
        FILTER ( ALLSELECTED ( 'Table' ), [Person] = MAX ( 'Table'[Person] ) )
    )
RETURN
    IF ( _count = _sum, 1 )
Month =
FORMAT (
    MAXX (
        FILTER ( ALLSELECTED ( 'Table' ), [Person] = MAX ( 'Table'[Person] ) ),
        [day]
    ),
    "mmmm"
)

Note:set the Assistance measure show items when the value is 1.

vstephenmsft_0-1646122164303.png

 

 

 

Best Regards,

Stephen Tao

 

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

It worked!

 

Many thanks,

Jos_Woolley
Solution Sage
Solution Sage

Perhaps these two measures:

Assistance =
VAR MyTable =
    ADDCOLUMNS(
        ADDCOLUMNS(
            'Table',
            "Concat",
                CONCATENATEX(
                    FILTER(
                        'Table',
                        'Table'[Person] = EARLIER( 'Table'[Person] )
                            && 'Table'[day] <= EARLIER( 'Table'[day] )
                    ),
                    'Table'[Assist],
                    ,
                    'Table'[day], ASC
                )
        ),
        "Check",
            0
                + ( VALUE( RIGHT( [Concat], 3 ) ) = 111 )
    )
RETURN
    0
        + (
            SUMX( MyTable, 0 + ( [Check] > 0 ) ) > 0
        )

 

Month =
VAR MyTable =
    ADDCOLUMNS(
        ADDCOLUMNS(
            'Table',
            "Concat",
                CONCATENATEX(
                    FILTER(
                        'Table',
                        'Table'[Person] = EARLIER( 'Table'[Person] )
                            && 'Table'[day] <= EARLIER( 'Table'[day] )
                    ),
                    'Table'[Assist],
                    ,
                    'Table'[day], ASC
                )
        ),
        "Check",
            0
                + ( VALUE( RIGHT( [Concat], 3 ) ) = 111 )
    )
RETURN
    FORMAT( MAXX( MyTable, IF( [Check] > 0, 'Table'[day] ) ), "mmmm" )

which can then be placed into, for example, a simple Table visual alongside the Person field.

Regards

Greg_Deckler
Community Champion
Community Champion

@xrieraca You could use a repeating counter like Cthulhu. https://community.powerbi.com/t5/Quick-Measures-Gallery/Cthulhu/m-p/509739#M211



Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
DAX For Humans

DAX is easy, CALCULATE makes DAX hard...

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

December 2025 Power BI Update Carousel

Power BI Monthly Update - December 2025

Check out the December 2025 Power BI Holiday Recap!

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.