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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
mantaga
Frequent Visitor

Calculate Previousday with applied date filter

Hi,

I'm analyzing the gorgeous Corona Power BI Report provided by zammikahan (original Link)

Right now I'm stuck at some point. I want to analyze new confirmed cases. If there's no date filter added, everything works fine.

The issue appears, when I'm filtering on a specific date. (See screenshot 2)

 

I can't resolve where the value of 411 is coming from. It should be yesterday's value (23.892).

As a result "confirmed cases" should still be 3.743 (27.635 - 23.892) in the second screenshot.

 

New confirmed cases yesterday temp = 

 CALCULATE(SUM('Corona Summary'[Confirmed Cases]),  PREVIOUSDAY('Corona Summary'[Date]))

 

It seems like the previousday filter isn't applied if I'm filtering on a specific date. Is there a way to bypass this behaviour ? 

Maybe someone has an idea.

Thanks a lot

Screenshot 2020-03-21 at 14.13.56.pngScreenshot 2020-03-21 at 14.11.19.png

 

pbix file

 

1 ACCEPTED SOLUTION
V-pazhen-msft
Community Support
Community Support

@mantaga 

Previousday() returns a table of dates, when you filter the date, the context will change dynamically. Try add ALL(Corona Summary) as another filter behind. 

 

New confirmed cases yesterday temp = 

 CALCULATE(SUM('Corona Summary'[Confirmed Cases]), PREVIOUSDAY('Corona Summary'[Date]),ALL('Corona Summary'))

 

You may also need ALL(Corona Summary) for other measures, for example:

 

New Confirmed Cases = 
VAR vToday = MAX('Corona Summary'[Date]) 
VAR vYesterday = MAX('Corona Summary'[Date]) -1 
RETURN CALCULATE(SUM('Corona Summary'[Confirmed Cases]), 'Corona Summary'[Date] = vToday,ALL('Corona Summary')) - CALCULATE(SUM('Corona Summary'[Confirmed Cases]), 'Corona Summary'[Date] = vYesterday,ALL('Corona Summary'))

 

 

Paul Zheng
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

3 REPLIES 3
V-pazhen-msft
Community Support
Community Support

@mantaga 

Previousday() returns a table of dates, when you filter the date, the context will change dynamically. Try add ALL(Corona Summary) as another filter behind. 

 

New confirmed cases yesterday temp = 

 CALCULATE(SUM('Corona Summary'[Confirmed Cases]), PREVIOUSDAY('Corona Summary'[Date]),ALL('Corona Summary'))

 

You may also need ALL(Corona Summary) for other measures, for example:

 

New Confirmed Cases = 
VAR vToday = MAX('Corona Summary'[Date]) 
VAR vYesterday = MAX('Corona Summary'[Date]) -1 
RETURN CALCULATE(SUM('Corona Summary'[Confirmed Cases]), 'Corona Summary'[Date] = vToday,ALL('Corona Summary')) - CALCULATE(SUM('Corona Summary'[Confirmed Cases]), 'Corona Summary'[Date] = vYesterday,ALL('Corona Summary'))

 

 

Paul Zheng
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

 

 

Thanks for your support.

 

Your solution works perfectly fine 🙂

Greg_Deckler
Super User
Super User

See if my Time Intelligence the Hard Way provides a different way of accomplishing what you are going for.

https://community.powerbi.com/t5/Quick-Measures-Gallery/Time-Intelligence-quot-The-Hard-Way-quot-TIT...


@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

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