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

A new Data Days event is coming soon! This time we’re going bigger than ever. Fabric, Power BI, SQL, AI and more. Don't miss out.

Reply
Anonymous
Not applicable

Count days with decrease number

Hi all,

 

I have a table that is updated daily with confirmed cases of covid. I need to display the number of days that this number is declining, but I don´t know how to calculate this information.

 

I set up a simplified table to exemplify:

 

Datenew casesDays in decrease
01/08/2020200
02/08/2020151
03/08/2020122
04/08/2020113
05/08/2020300
06/08/2020500
07/08/2020700
08/08/2020451
09/08/2020302
10/08/2020173
11/08/2020164
12/08/2020180

 

Thanks!

1 ACCEPTED SOLUTION

Hi @Anonymous ,

 

Try this measure:

_Count_Decrease = 
VAR _tb = SUMMARIZE(ALL('Table'), 'Table'[Date], 'Table'[new cases], "Decrease",
                        VAR _previousDate = CALCULATE(MAX('Table'[Date]), FILTER(ALL('Table'), 'Table'[Date] < EARLIER('Table'[Date])))
                        RETURN
                            IF('Table'[new cases] < CALCULATE(SUM('Table'[new cases]), FILTER(ALL('Table'), 'Table'[Date] = _previousDate)), 1, 0)
)
VAR _currentDate = SELECTEDVALUE('Table'[Date])
VAR _firstZero = CALCULATE(MAX('Table'[Date]), FILTER(_tb, 'Table'[Date] <= _currentDate && [Decrease] = 0)) 
RETURN 
    SUMX(FILTER(_tb, 'Table'[Date] >= _firstZero && 'Table'[Date] <= _currentDate), [Decrease])

 

Capture.PNG



Did I answer your question? Mark my post as a solution!

Proud to be a Super User!



View solution in original post

5 REPLIES 5
amitchandak
Super User
Super User

@Anonymous ,

new column like new cases = sumx(filter(table, [date] =earlier([date])-1),[new cases])

 

You can this day vs last day like this with date table

This Day = CALCULATE(sum('order'[Qty]), FILTER(ALL('Date'),'Date'[Date]=max('Date'[Date])))
Last Day = CALCULATE(sum('order'[Qty]), FILTER(ALL('Date'),'Date'[Date]=max('Date'[Date])-1))
Last Day = CALCULATE(sum('order'[Qty]), previousday('Date'[Date]))

 

Last Day Non Continuous = CALCULATE([sales],filter(ALLSELECTED('Date'),'Date'[Date] =MAXX(FILTER(ALLSELECTED('Date'),'Date'[Date]<max('Date'[Date])),'Date'[Date])))
Day behind Sales = CALCULATE(SUM(Sales[Sales Amount]),dateadd('Date'[Date],-1,Day))
Diff COlumn = datediff(maxx(filter(Table,Table[Date]<earlier(Table[Date]) && Table[Numberf]= earlier(Table[Numberf]) ),Table[Date]) ,Table[Date],Day)

 

Power BI — Day Intelligence
https://medium.com/@amitchandak.1978/power-bi-day-intelligence-questions-time-intelligence-5-5-5c324...

 

To get the best of the time intelligence function. Make sure you have a date calendar and it has been marked as the date in model view. Also, join it with the date column of your fact/s. Refer :
https://radacad.com/creating-calendar-table-in-power-bi-using-dax-functions
https://www.archerpoint.com/blog/Posts/creating-date-table-power-bi
https://www.sqlbi.com/articles/creating-a-simple-date-table-in-dax/

See if my webinar on Time Intelligence can help: https://community.powerbi.com/t5/Webinars-and-Video-Gallery/PowerBI-Time-Intelligence-Calendar-WTD-Y...


Appreciate your Kudos.

 

 

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube
Anonymous
Not applicable

Hi  !

 

I'm so sorry, but I'm just starting with power bi.

In my model I already have a calendar table, I just did the relationship with report date with the calendar date.

 

After that, I should create measures with this part?

 

This Day = CALCULATE(sum('order'[Qty]), FILTER(ALL('Date'),'Date'[Date]=max('Date'[Date])))
Last Day = CALCULATE(sum('order'[Qty]), FILTER(ALL('Date'),'Date'[Date]=max('Date'[Date])-1))
Last Day = CALCULATE(sum('order'[Qty]), previousday('Date'[Date]))

 

Last Day Non Continuous = CALCULATE([sales],filter(ALLSELECTED('Date'),'Date'[Date] =MAXX(FILTER(ALLSELECTED('Date'),'Date'[Date]<max('Date'[Date])),'Date'[Date])))
Day behind Sales = CALCULATE(SUM(Sales[Sales Amount]),dateadd('Date'[Date],-1,Day))
Diff COlumn = datediff(maxx(filter(Table,Table[Date]<earlier(Table[Date]) && Table[Numberf]= earlier(Table[Numberf]) ),Table[Date]) ,Table[Date],Day)

 

Thank you!

Hi @Anonymous ,

 

Try this measure:

_Count_Decrease = 
VAR _tb = SUMMARIZE(ALL('Table'), 'Table'[Date], 'Table'[new cases], "Decrease",
                        VAR _previousDate = CALCULATE(MAX('Table'[Date]), FILTER(ALL('Table'), 'Table'[Date] < EARLIER('Table'[Date])))
                        RETURN
                            IF('Table'[new cases] < CALCULATE(SUM('Table'[new cases]), FILTER(ALL('Table'), 'Table'[Date] = _previousDate)), 1, 0)
)
VAR _currentDate = SELECTEDVALUE('Table'[Date])
VAR _firstZero = CALCULATE(MAX('Table'[Date]), FILTER(_tb, 'Table'[Date] <= _currentDate && [Decrease] = 0)) 
RETURN 
    SUMX(FILTER(_tb, 'Table'[Date] >= _firstZero && 'Table'[Date] <= _currentDate), [Decrease])

 

Capture.PNG



Did I answer your question? Mark my post as a solution!

Proud to be a Super User!



Pragati11
Super User
Super User

HI @Anonymous ,

 

On what basis you want to count days in declining manner?

I am not able to understand the issue clearly. Can you add more details please?

 

Thanks,

Pragati

Best Regards,

Pragati Jain


MVP logo


LinkedIn | Twitter | Blog YouTube 

Did I answer your question? Mark my post as a solution! This will help others on the forum!

Appreciate your Kudos!!

Proud to be a Super User!!

Anonymous
Not applicable

Hi  !

 

The count should consider the number of consecutive days in which the number of cases (compared to the previous day) shows a decline.

 

Example:
08/26: 40 cases
08/27: 30 cases
08/28: 20 cases

Today I should display 3 days.

 

If the table was like:
08/26: 18 cases
08/27: 30 cases
08/28: 20 cases

Today I should display 1 day

 

If the number on 08/28 was a increase, I should display 0 ...

Helpful resources

Announcements
May Power BI Update Carousel

Power BI Monthly Update - May 2026

Check out the May 2026 Power BI update to learn about new features.

Fabric SQL PBI Data Days

Data Days 2026 coming soon!

Sign up to receive a private message when registration opens and key events begin.

New to Fabric survey Carousel

New to Fabric Survey

If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.