Proper Data set from Date Range

MrMishutka

New Member
Joined
Feb 6, 2024
Messages
2
Office Version
  1. 365
Platform
  1. MacOS
To take a table such as this
Screenshot 2024-02-06 at 17.22.16.png

And turn it into a table like this
Screenshot 2024-02-06 at 17.22.40.png

Is pretty easy in Power Query
Power Query:
let
  Source = Excel.CurrentWorkbook(){[Name="BaseData"]}[Content],
  #"Changed column type" = Table.TransformColumnTypes(Source, {{"Start", type date}, {"End", type date}, {"Type", type text}, {"Description", type text}}),
  #"Added number of days" = Table.AddColumn(#"Changed column type", "Days", each Duration.Days([End] - [Start]), Int64.Type),
  #"Add list" = Table.AddColumn(#"Added number of days", "List", each {0..[Days]}),
  #"Expanded list" = Table.ExpandListColumn(#"Add list", "List"),
  #"Added dates" = Table.AddColumn(#"Expanded list", "Date", each Date.AddDays([Start],[List]), type date),
  #"Removed other columns" = Table.SelectColumns(#"Added dates", {"Date", "Type", "Description"})
in
  #"Removed other columns"
But does anyone know how to do this with dynamic array formulae? I have been trying with a combination of BYROW, SEQUENCE and TOCOL, but keep geeting a #VALUE error because it says I have nested arrays.

I got close with a list of dates using in cell I2
Excel Formula:
=SEQUENCE(1,OFFSET(BaseData,H2-1,1,1,1)-OFFSET(BaseData,H2-1,0,1,1)+1,OFFSET(BaseData,H2-1,0,1,1),1)
where H2 contained
Excel Formula:
=SEQUENCE(ROWS(BaseData))

I could copy this down against each row in the table and then use
Excel Formula:
=TOCOL(I2#:I4#,1)
but the problem with this it is not dynamic and has to be updated everytime a new record is added to the table, in which case I might as well use the simple Power Query method above.

I tried to change H2 to H2# throughout the formula and I get a #VALUE! error. Equally if I change I2 to
Excel Formula:
=BYROW(H2#,LAMBDA(r,SEQUENCE(1,OFFSET(BaseData,r-1,1,1,1)-OFFSET(BaseData,r-1,0,1,1)+1,OFFSET(BaseData,r-1,0,1,1),1)))
I get a #CALC! (Nested Arrays) error.

Does anyone have any suggestions how I can get a proper data set using dynamic array formulae?
 

Excel Facts

How to create a cell-sized chart?
Tiny charts, called Sparklines, were added to Excel 2010. Look for Sparklines on the Insert tab.
Hi & welcome to MrExcel.
How about
Fluff.xlsm
ABCDEFGH
1
201/01/202403/01/2024Holidayabc01/01/2024Holidayabc
305/01/202408/01/2024Workmno02/01/2024Holidayabc
402/02/202407/02/2024Workxyz03/01/2024Holidayabc
505/01/2024Workmno
606/01/2024Workmno
707/01/2024Workmno
808/01/2024Workmno
902/02/2024Workxyz
1003/02/2024Workxyz
1104/02/2024Workxyz
1205/02/2024Workxyz
1306/02/2024Workxyz
1407/02/2024Workxyz
15
Sheet5
Cell Formulas
RangeFormula
F2:H14F2=LET(d,B2:B4-A2:A4+1,m,MAX(d),s,SEQUENCE(,m),HSTACK(TOCOL(IF(s<=d,A2:A4+SEQUENCE(,m,0),1/0),2),TOCOL(IF(s<=d,C2:C4,1/0),2),TOCOL(IF(s<=d,D2:D4,1/0),2)))
Dynamic array formulas.
 
Upvote 0
2=LET(d,B2:B4-A2:A4+1,m,MAX(d),s,SEQUENCE(,m),HSTACK(TOCOL(IF(s<=d,A2:A4+SEQUENCE(,m,0),1/0),2),TOCOL(IF(s<=d,C2:C4,1/0),2),TOCOL(IF(s<=d,D2:D4,1/0),2)))
Thats really cool, thanks. Now I will just have to work out why it is working :)
 
Upvote 0
You're welcome & thanks for the feedback.
 
Upvote 0

Forum statistics

Threads
1,223,214
Messages
6,170,771
Members
452,353
Latest member
strainu

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top