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.

MBAS on Demand

2021 Release Wave 2 Plan

Power Platform release plan for the 2021 release wave 2 describes all new features releasing from October 2021 through March 2022.

Get Ready for Power BI Dev Camp

Microsoft named a Leader in The Forrester Wave

Microsoft received the highest score of any vendor in both the strategy and current offering categories.

R2 (Green) 768 x 460px.png

Microsoft Dynamics 365 & Power Platform User Professionals

DynamicsCon is a FREE, 4 half-day virtual learning experience for 11,000+ Microsoft Business Application users and professionals.

Top Solution Authors
Top Kudoed Authors