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

Score big with last-minute savings on the final tickets to FabCon Vienna. Secure your discount

Reply
Anonymous
Not applicable

Dax Measure to calculate number of days status is red

I need help with writing a dax measure to calculate the number of days the status is red.

 

Data

Krkrang_0-1657004534599.png

For my data, the status that is red = 1

 

I have a data that is coming in day/night. I want to calculate from today how many days it have been red (both day and night must be red). If the lastest data is not red then it will be 0. 

 

 

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

Hi @Anonymous ,

According to your description, I create a sample.

vkalyjmsft_0-1657261100782.png

I add more rows to test. If your date and Day/Night are in the same column, firstly split the column in Power Query, otherwise the column can't be in the date type.

Here's my solution, create a measure.

COUNT =
VAR _T =
    ADDCOLUMNS (
        'Table',
        "Red",
            IF (
                COUNTROWS (
                    FILTER (
                        ALL ( 'Table' ),
                        'Table'[Date] = EARLIER ( 'Table'[Date] )
                            && 'Table'[B status] <> 1
                    )
                ) = 0,
                1
            )
    )
VAR _Max =
    MAXX ( FILTER ( _T, [B status] <> 1 ), [Date] )
RETURN
    CALCULATE (
        DISTINCTCOUNT ( 'Table'[Date] ),
        FILTER ( _T, [Red] = 1 && [Date] > _Max && [Date] <= TODAY () )
    )

Get the correct result.

vkalyjmsft_1-1657261341391.png

I attach my sample below for reference.

 

Best Regards,
Community Support Team _ kalyj

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

View solution in original post

1 REPLY 1
v-yanjiang-msft
Community Support
Community Support

Hi @Anonymous ,

According to your description, I create a sample.

vkalyjmsft_0-1657261100782.png

I add more rows to test. If your date and Day/Night are in the same column, firstly split the column in Power Query, otherwise the column can't be in the date type.

Here's my solution, create a measure.

COUNT =
VAR _T =
    ADDCOLUMNS (
        'Table',
        "Red",
            IF (
                COUNTROWS (
                    FILTER (
                        ALL ( 'Table' ),
                        'Table'[Date] = EARLIER ( 'Table'[Date] )
                            && 'Table'[B status] <> 1
                    )
                ) = 0,
                1
            )
    )
VAR _Max =
    MAXX ( FILTER ( _T, [B status] <> 1 ), [Date] )
RETURN
    CALCULATE (
        DISTINCTCOUNT ( 'Table'[Date] ),
        FILTER ( _T, [Red] = 1 && [Date] > _Max && [Date] <= TODAY () )
    )

Get the correct result.

vkalyjmsft_1-1657261341391.png

I attach my sample below for reference.

 

Best Regards,
Community Support Team _ kalyj

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

Helpful resources

Announcements
August Power BI Update Carousel

Power BI Monthly Update - August 2025

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

August 2025 community update carousel

Fabric Community Update - August 2025

Find out what's new and trending in the Fabric community.