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

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