Forum Discussion

marypal's avatar
marypal
Frequent Visitor
3 years ago

How to create 7-day bins

Hi,

I need help with the following task.

We have for example a table with orders and date. I need to calculate how many orders were created every week and display that on the chart. The 7-day bins should be created in the following way: the last date of a chosen on a slicer month is our final date, then we go back every 7 days, the last bin will include the days from the previous month such that to complete the whole period of 7 days.

For example, we chose October 2022.
1st bin: 27.09.22 - 03.10.22
2nd bin: 04.10.22 - 10.10.22 
3rd bin: 11.10.22 - 17.10.22
4th bin: 18.10.22 - 24.10.22
5th bin: 25.10.22 - 31.10.22

Could you please suggest how this can be implemented.
I tried Power BI bins but it's impossible to implement the above logic.

 

Many thanks


 

 

5 Replies

  • rajulshah's avatar
    rajulshah
    Icon for Resident Rockstar rankResident Rockstar

    marypal 

     

    You can create bins using the following logic:

    This would create bins in the date table. Then you can create another column to get the last date of the week with the following DAX:

    WeekLastDate = Dates[Date (bins)] + 6

     

    Please let me know if this didn't work.

    • marypal's avatar
      marypal
      Frequent Visitor

      Hello rajulshah ,

      Thank you for your reply.

      Unfortunately, this did not work. In the report I have a slicer to choose a month. So it is not possible to choose the last date of the period to create bins, they are dynamic.

      • rajulshah's avatar
        rajulshah
        Icon for Resident Rockstar rankResident Rockstar

        marypal 

        So that would work, right?
        Can you give me an example of what the date slicer selection is and how this solution doesn't work for you?