# Appending data to a filtered array



## Tipsey (Jan 1, 2023)

I have a table with a lot of data that I have extracted using the filter function.  I would like to add a date column to this array, as well as a column to indicate which sheet it came from.
I have been able to accomplish this by using hstack and an if clause and then repeating the same filter for the data, however it makes it very messy and less maintanable.  Is there a more elegant solution for this?


----------



## jasonb75 (Jan 2, 2023)

Posting your existing formula would be helpful. With just a brief written description there is a lot that is open to misinterpretation.

From what you have said, I would imagine that your current formula is going to be as good as you will get, although it may be possible to improve efficiency and maintenance by making use of the LET and / or LAMBDA functions.


----------



## jdellasala (Jan 2, 2023)

I would recommend just using HSTACK
Book1ABCDEFGHIJ134384001/02/202334384001/02/2023238282801/03/202338282801/03/2023329101501/04/202329101501/04/2023Sheet1Cell FormulasRangeFormulaA1:C3A1=RANDARRAY(3,3,10,40,1)E1:E3E1=SEQUENCE(3,,DATEVALUE("1/2/2023"))G1:J3G1=HSTACK(A1#,E1#)Dynamic array formulas.


----------



## Tipsey (Jan 3, 2023)

jdellasala said:


> I would recommend just using HSTACK
> Book1ABCDEFGHIJ134384001/02/202334384001/02/2023238282801/03/202338282801/03/2023329101501/04/202329101501/04/2023Sheet1Cell FormulasRangeFormulaA1:C3A1=RANDARRAY(3,3,10,40,1)E1:E3E1=SEQUENCE(3,,DATEVALUE("1/2/2023"))G1:J3G1=HSTACK(A1#,E1#)Dynamic array formulas.


Hstack works.  My goal is to attach a date from a single cell reference to the result of a filter function on a table of data.

I can make it attach it to the first record but Subsequent ones have an error.  The include argument in my filter is rather complex and I am looking to avoid duplicating it just to end up with the same sized array to hstack.


----------



## jdellasala (Jan 3, 2023)

I assume you used RANDARRAY to simulate data, but if the date is going to be what you have, no need to have it in a separate column, just put it in HSTACK
PositionsRaw.xlsxABCDEFGH128393728393701/02/2023238224038224001/03/2023337132137132101/04/2023Sheet6Cell FormulasRangeFormulaA1:C3A1=RANDARRAY(3,3,10,40,1)E1:H3E1=HSTACK(A1#,SEQUENCE(3,,DATEVALUE("1/2/2023")))Dynamic array formulas.


----------



## Fluff (Jan 3, 2023)

Can you post a sample of your data, including the formula.

MrExcel has a tool called “XL2BB” that lets you post samples of your data that will allow us to copy/paste it to our Excel spreadsheets, so we can work with the same copy of data that you are. Instructions on using this tool can be found here: XL2BB Add-in

Note that there is also a "Test Here” forum on this board. This is a place where you can test using this tool (or any other posting techniques that you want to test) before trying to use those tools in your actual posts.


----------

