Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Compete to become Power BI Data Viz World Champion! First round ends August 18th. Get started.

Reply
durgaraop21
Helper II
Helper II

How to create 7-day bins

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.

 

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.
Can you please suggest in Power Query Editor
Example:

Please find the below screenshot:

durgaraop21_0-1707390392998.png

 

1 ACCEPTED SOLUTION
sevenhills
Super User
Super User

Try this PQ: Modify the start and end date to your needs i.e., date(2022,9,27) and date(2023,1,4)

 

let
    Source = List.Generate(()=>[x=#date(2022,9,27)], each [x]<=#date(2023, 1, 4), each [x=Date.AddWeeks([x],1)], each [x]),
 

    #"Converted to Table" = Table.FromList(Source, Splitter.SplitByNothing(), null, null, ExtraValues.Error),
    #"Renamed Columns" = Table.RenameColumns(#"Converted to Table",{{"Column1", "Start Date"}}),
    #"Changed Type" = Table.TransformColumnTypes(#"Renamed Columns",{{"Start Date", type date}}),
    #"Sorted Rows" = Table.Sort(#"Changed Type",{{"Start Date", Order.Ascending}}),
    #"Added Custom" = Table.AddColumn(#"Sorted Rows", "End Date", each Date.AddDays([Start Date], 6), type date),
    #"Added Index" = Table.AddIndexColumn(#"Added Custom", "Index", 1, 1, Int64.Type)
in
    #"Added Index"

 Output:

sevenhills_0-1707419903358.png

Hope it helps!

 

 

View solution in original post

1 REPLY 1
sevenhills
Super User
Super User

Try this PQ: Modify the start and end date to your needs i.e., date(2022,9,27) and date(2023,1,4)

 

let
    Source = List.Generate(()=>[x=#date(2022,9,27)], each [x]<=#date(2023, 1, 4), each [x=Date.AddWeeks([x],1)], each [x]),
 

    #"Converted to Table" = Table.FromList(Source, Splitter.SplitByNothing(), null, null, ExtraValues.Error),
    #"Renamed Columns" = Table.RenameColumns(#"Converted to Table",{{"Column1", "Start Date"}}),
    #"Changed Type" = Table.TransformColumnTypes(#"Renamed Columns",{{"Start Date", type date}}),
    #"Sorted Rows" = Table.Sort(#"Changed Type",{{"Start Date", Order.Ascending}}),
    #"Added Custom" = Table.AddColumn(#"Sorted Rows", "End Date", each Date.AddDays([Start Date], 6), type date),
    #"Added Index" = Table.AddIndexColumn(#"Added Custom", "Index", 1, 1, Int64.Type)
in
    #"Added Index"

 Output:

sevenhills_0-1707419903358.png

Hope it helps!

 

 

Helpful resources

Announcements
July PBI25 Carousel

Power BI Monthly Update - July 2025

Check out the July 2025 Power BI update to learn about new features.

August 2025 community update carousel

Fabric Community Update - August 2025

Find out what's new and trending in the Fabric community.

Top Solution Authors
Top Kudoed Authors