cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
sublog
Helper II
Helper II

Number of days going up or down

Working with the COVID-19 Power BI File trying to make some modifications. 

 

I am looking to create a measure that basically tells me the number of days that daily cases has been going up or down in a row. 

 

If the number of daily cases has gone up 3 days in a row, I would like the measure to return 3. If the number of cases has gone up 10 days in a row I'd like to return 10. 

 

Spent some time trying to search for examples of this, but I couldn't find anything like this in particular. 

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

Hi @sublog ,

 

We can use the following measure to meet your requirement.

 

Measure = 
VAR t =
    SUMMARIZE (
        FILTER ( ALLSELECTED ( 'Table' ), 'Table'[Date] <= MIN ( 'Table'[Date] ) ),
        'Table'[Date],
        "dateTotal", SUM ( 'Table'[Total] )
    )
VAR t2 =
    ADDCOLUMNS (
        t,
        "isDecrease",
        VAR d = [Date]
        RETURN
            IF (
                [dateTotal]
                    < SUMX ( FILTER ( t, 'Table'[Date] = d - 1 ), [dateTotal] ),
                1,
                0
            )
    )
VAR last0dat =
    MAXX ( FILTER ( t2, [isDecrease] = 0 ), [Date] )
RETURN
    IF (
        MAXX ( FILTER ( t2, 'Table'[Date] = MIN ( 'Table'[Date] ) ), [isDecrease] ) = 1,
        DATEDIFF ( last0dat, MIN ( 'Table'[Date] ), DAY ),
        0
)

 

We can get the result like this,

 

Number 1.jpg

 

If it doesn’t meet your requirement, could you please show the exact expected result based on the table that we have shared?

BTW, pbix as attached.

 

Best regards,


Community Support Team _ zhenbw
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

2 REPLIES 2
v-zhenbw-msft
Community Support
Community Support

Hi @sublog ,

 

We can use the following measure to meet your requirement.

 

Measure = 
VAR t =
    SUMMARIZE (
        FILTER ( ALLSELECTED ( 'Table' ), 'Table'[Date] <= MIN ( 'Table'[Date] ) ),
        'Table'[Date],
        "dateTotal", SUM ( 'Table'[Total] )
    )
VAR t2 =
    ADDCOLUMNS (
        t,
        "isDecrease",
        VAR d = [Date]
        RETURN
            IF (
                [dateTotal]
                    < SUMX ( FILTER ( t, 'Table'[Date] = d - 1 ), [dateTotal] ),
                1,
                0
            )
    )
VAR last0dat =
    MAXX ( FILTER ( t2, [isDecrease] = 0 ), [Date] )
RETURN
    IF (
        MAXX ( FILTER ( t2, 'Table'[Date] = MIN ( 'Table'[Date] ) ), [isDecrease] ) = 1,
        DATEDIFF ( last0dat, MIN ( 'Table'[Date] ), DAY ),
        0
)

 

We can get the result like this,

 

Number 1.jpg

 

If it doesn’t meet your requirement, could you please show the exact expected result based on the table that we have shared?

BTW, pbix as attached.

 

Best regards,


Community Support Team _ zhenbw
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

sublog
Helper II
Helper II

For the table below, I would count the consecutive number of days where Test = 1 or 0. 

 

The row for 4/18/2020, the downtrend measure would = 2

The row for 4/17/2020, the downtrend measure would = 1
 

syyOWPa

Helpful resources

Announcements
PBI_User Group Leader_768x460.jpg

Manage your user group events

Check out the News & Announcements to learn more.

Welcome Super Users.jpg

Super User Season 2

Congratulations, the new Super User Season 2 for 2021 has started!

Community Connections 768x460.jpg

Community & How To Videos

Check out the new Power Platform Community Connections gallery!

Teds Dev Camp Oct. 2021 768x460.jpg

Power BI Dev Camp - October 28th, 2021

Mark your calendars and join us for our next Power BI Dev Camp!