Forum Discussion

ChristianDGreat's avatar
ChristianDGreat
Icon for Resolver I rankResolver I
4 years ago
Solved

Previous Week Sales - Logic (cumulative)

Hello I encounter this request and having a hard time creating a dax formula for this.

 

so basically I have this table

 

DateDay of WeekSales
25-SepSunday123
26-SepMonday213
27-SepTuesday32
28-SepWednesday2
29-SepThursday23
30-SepFriday23
1-OctSaturday23
2-OctSunday123
3-OctMonday123
4-OctTuesday232
5-OctWednesday32
6-OctThursday3
7-OctFriday23
8-OctSaturday2
9-OctSunday32
10-OctMonday3
11-OctTuesday23

 

The goal is to get the total sales last week based on where we at this week.

Lets assume today is 10/12 (wednesday), basically we will only have data up to tuesday.
The goal is to get the sum of last week from sunday to tuesday (again last week)(upto tuesday only because today is wednesday).

So basically the answer should be 478

 

which is the sum of this from last week (sunday to tuesday last week) - this is because today is Wednesday (in our testing or in this case)

DateDay of WeekSales
2-OctSunday123
3-OctMonday123
4-OctTuesday232

 

so if today's date is 10/15 (saturday) the result should be - 536
Here's the explanation table for it

DateDay of WeekSales
2-OctSunday123
3-OctMonday123
4-OctTuesday232
5-OctWednesday32
6-OctThursday3
7-OctFriday23



  • ChristianDGreat , As want to display Last week Trend , Make sure there is no date filter, or if there is date filter it should come from independent date table

     

    LWTD Today =
    var _min = TODAY() -WEEKDAY(TODAY(),1) -6 //Sumday week start
    var _max = today() -7
    return CALCULATE([Net], FILTER('Date','Date'[Date] >=_min && 'Date'[Date] <= _max))

     

     

    LWTD Today =

    //Date1 is independent Date table, Date is joined with Table
    var _today = maxx(allselected(Date1),Date1[Date])
    var _min =_today -WEEKDAY(_today ,1) -6 //Sunday week start
    var _max = _today -7
    return CALCULATE([Net], FILTER('Date','Date'[Date] >=_min && 'Date'[Date] <= _max))

     

    https://medium.com/chandakamit/cheat-sheet-power-bi-time-intelligence-formulas-using-today-654f26e27304

     

    Need of an Independent Table in Power BI - Exclude: https://youtu.be/lOEW-YUrAbE

1 Reply

  • ChristianDGreat , As want to display Last week Trend , Make sure there is no date filter, or if there is date filter it should come from independent date table

     

    LWTD Today =
    var _min = TODAY() -WEEKDAY(TODAY(),1) -6 //Sumday week start
    var _max = today() -7
    return CALCULATE([Net], FILTER('Date','Date'[Date] >=_min && 'Date'[Date] <= _max))

     

     

    LWTD Today =

    //Date1 is independent Date table, Date is joined with Table
    var _today = maxx(allselected(Date1),Date1[Date])
    var _min =_today -WEEKDAY(_today ,1) -6 //Sunday week start
    var _max = _today -7
    return CALCULATE([Net], FILTER('Date','Date'[Date] >=_min && 'Date'[Date] <= _max))

     

    https://medium.com/chandakamit/cheat-sheet-power-bi-time-intelligence-formulas-using-today-654f26e27304

     

    Need of an Independent Table in Power BI - Exclude: https://youtu.be/lOEW-YUrAbE