Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
5 years ago
Solved

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!

 

 

  • Anonymous's avatar
    Anonymous
    5 years ago

    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)

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

     

    Best Regards,

    Jay

3 Replies

  • 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's avatar
      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

  • Anonymous's avatar
    Anonymous
    Not applicable

    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)

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

     

    Best Regards,

    Jay