cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Anonymous
Not applicable

Next and previous day values

Hello to PowerBI community,

I have 2 tables

 

1st

CodeDescription
1x
2y
3z
4w

 

2nd

DateCodeValue
3/5/2021158
3/5/2021265
3/5/2021312
3/5/2021443
3/6/2021287
3/6/2021354
3/6/2021412

I had made a relationship on code in order to have this picture

DateCodeValueDescription
3/5/2021158x
3/5/2021265y
3/5/2021312z
3/5/2021443w
3/6/2021287y
3/6/2021354z
3/6/2021412w
3/7/202110x
3/7/202120y
3/7/202130z
3/7/202140w

I don't want to use filter relative date. I want to create a measure display next day value and if next day values are 0 display previous day. As you can see 3/7/2021 value column are all 0 so I want to see previous day (3/6/2021) values. Also keep in mind that I want to use in my table all the columns except date column and my data connectivity mode is Import.

 

Thank you in advance for your help!

 

 

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

Hi @Anonymous ,

 

Check the measure and the result.

Measure = 
var _next = CALCULATE(SUM('Table 2'[Value]),FILTER(ALL('Table 2'),'Table 2'[Date]=SELECTEDVALUE('Table 2'[Date])+1&&'Table 2'[Code]=SELECTEDVALUE('Table 1'[Code])))
var _previous = CALCULATE(SUM('Table 2'[Value]),FILTER(ALL('Table 2'),'Table 2'[Date]=SELECTEDVALUE('Table 2'[Date])-1&&'Table 2'[Code]=SELECTEDVALUE('Table 1'[Code])))
return
IF(_next=0,_previous,_next)

6.PNG

If the result is not what you want, please show the expected result.

 

Best Regards,

Jay

Community Support Team _ Jay
If this post helps, then please consider Accept it as the solution
to help the other members find it.

View solution in original post

3 REPLIES 3
v-jayw-msft
Community Support
Community Support

Hi @Anonymous ,

 

Check the measure and the result.

Measure = 
var _next = CALCULATE(SUM('Table 2'[Value]),FILTER(ALL('Table 2'),'Table 2'[Date]=SELECTEDVALUE('Table 2'[Date])+1&&'Table 2'[Code]=SELECTEDVALUE('Table 1'[Code])))
var _previous = CALCULATE(SUM('Table 2'[Value]),FILTER(ALL('Table 2'),'Table 2'[Date]=SELECTEDVALUE('Table 2'[Date])-1&&'Table 2'[Code]=SELECTEDVALUE('Table 1'[Code])))
return
IF(_next=0,_previous,_next)

6.PNG

If the result is not what you want, please show the expected result.

 

Best Regards,

Jay

Community Support Team _ Jay
If this post helps, then please consider Accept it as the solution
to help the other members find it.
amitchandak
Super User
Super User

@Anonymous , with a date table you can use time intelligence

Last Day = CALCULATE(sum('Table'[Value]), previousday('Date'[Date]))

nextDay = CALCULATE(sum('Table'[Value]), nextday('Date'[Date]))

 

 

Other examples

Day behind Sales = CALCULATE(SUM(Sales[Sales Amount]),dateadd('Date'[Date],-1,Day))

 

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))

 

Day Intelligence - Last day, last non continous day
https://medium.com/@amitchandak.1978/power-bi-day-intelligence-questions-time-intelligence-5-5-5c3243d1f9



New Power BI Features
Datamarts: https://youtu.be/8tskWsJTEpg
Field Parameters : https://youtu.be/lqF3Wa1FllE?t=70
Did I answer your question? Mark my post as a solution! Appreciate your Kudos!! !!
Dashboard of My Blogs !! Connect on Linkedin !! Proud to be a Super User!
Want To Learn Power BI
Learn Power BI Beginners !! Advance Power BI Concepts !! Power BI For Tableau User !! Learn Power BI in Hindi !!
!! Subscribe to my youtube Channel !!
Anonymous
Not applicable

I don't have a date table. I have a column on my table which contains date data.

 

So those functions don't work. They return an empty table. Is this another way to solve this?

 

Thank you

Helpful resources

Announcements
June 2022 update 768X460.jpg

Check it out!

Click here to read more about the June 2022 updates!

Power Platform Conf 2022 768x460.jpg

Join us for Microsoft Power Platform Conference

The first Microsoft-sponsored Power Platform Conference is coming in September. 100+ speakers, 150+ sessions, and what's new and next for Power Platform.

Power BI Dev Camp Session 23 768x460.jpg

Check it Out!

Mark your calendars and join us on Thursday, June 30 at 11a PDT for a great session with Ted Pattison!

June 20 episode 7 with aka link 768x460.jpg

The Power BI Community Show

Join us on June 20 at 11 am PDT when Kim Manis shares the latest on Azure Synapse analytics, the Microsoft Intelligent Data Platform, and notable Power BI Updates from Microsoft Build 2022.

Top Solution Authors