cancel
Showing results for
Did you mean:  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  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 =
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, 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.

2 REPLIES 2  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 =
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, 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.  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   