Call spill range within dynamic array formula - excel

I am trying to query a list of sales stored in Excel using a dynamic array formula referencing a spill range and this does not work.
Here is the context:
I have a table tabSales containing the sales, with the following data : date, customer, amount, year (calculated using =YEAR([Date])
I want to display on another sheet the amount sold year by year for a given customer to be selected by the user in cell B1 (named SelCust)
Here is what I have tried on the report sheet:
I have used the UNIQUE and FILTER functions to make the report display on column D the years where the selected customer has actually bought something : =UNIQUE(FILTER(tabSales[Year],tabSales[Customer]=SelCust)) (formula input in cell D2)
I have then tried to use the SUM and FILTER functions and Excel's spill range feature to calculate for each year the total amount sold to the selected customer : =SUM(FILTER(tabSales[Amount],(tabSales[Year]=D2#)*(tabSales[Customer]=SelCust))) (formula input in E2)
Unfortunately, this last formula unfortunately does not work:
Excel returns #N/A in E2
Cell E2 does not spill over E3, E4, ...
The lack of spilling makes me wonder whether the spill range reference within the FILTER function is recognized...
How could I get this formula to work ?
Sales table
Non-working formula

Use SUMIFS():
=SUMIFS(tabSales[Amount],tabSales[Year],D2#,tabSales[Customer],SelCust)
This should return an array properly.
If one wants to do both columns in one dynamic formula we can use LET and CHOOSE:
=let(
slcust,tabSales[Customer],
amt,tabSales[Amount],
yr,tabSales[Year],
unYr,UNIQUE(FILTER(yr,slcust=SelCust)),
sm,SUMIFS(amt,yr,unyr,slcust,SelCust),
Choose({1,2},unyr,sm))

Related

Populate cells in excel with a function incorporating a filter and an incrementing column paramater

Resource Planning Image
In column H1 I use the following to create a number of columns with month data based on the project length (D2) and start date B2 =EDATE($B$2, SEQUENCE(1, $D$2, 0))
The data in A13 is created with the following filter and will be variable in size =FILTER(FILTER(AllStaffProjectAllocationTbl,AllStaffProjectAllocationTbl[Project Name]=A2), {1,1,0,1,0,0,1,0,0,1})
I'd like to automate the data generated from cell H3 in the same way that H1 works, so pasting in one formula that then populates all the subsequent cells from the start of the project (B2) up to the duration of the project (D2).
Here's the forumla in cell H3 that is used to calculate the monthly cost based on the salaries in the resource sumary, and comparing the start and end dates with H1 to see if they are active on the project that month =SUMIFS($E$13:$E$20,$C13:$C20, "<="&H1, $D13:$D20, ">="&H1)
I'd like to find a way to modify this to support the variable Filter size for the resource summary whilst also just pasting in one function in to H3 that will then populate the subsequent cells, modifying H1 to H2 and so on for the duration of the project. Any help will be appreciated.
Additionally, is there a way to populate the column data from G13 downwards from the filter data in A13 such that it has the same names? At the moment I have =A13 and drag it down for the size of the generated filter, it'd be great if this was automated.
The "Active Staff" row can be dynamically calculated with the following formula in cell H2:
=MMULT(SEQUENCE(1,ROWS($A$13#),1,0),($H$1#>=OFFSET($A$13#,0,2,,1))*($H$1#<=OFFSET($A$13#,0,3,,1)))
Both, the data array of A13# and the dates vector of H1# are being addressed as arrays, so the formula above will adapt to any length.
Following the same logic, the "Salary Costs" can be dynamically calculated in H3 as follows:
=MMULT(SEQUENCE(1,ROWS($A$13#),1,0),($H$1#>=OFFSET($A$13#,0,2,,1))*($H$1#<=OFFSET($A$13#,0,3,,1))*OFFSET($A$13#,0,4,,1))
This is pretty much the same formula except for additional multiplication with the "Salary Monthly" vector.
Note that this solution assumes the "Start Date" column of A13 to always be the 3rd column, the "End Date" column to always be the 4th, and the "Salary Monthly" column to always be the 5th. You can see that assumption in the fixed number given to the column index in the OFFSET functions.

How arrange dates from min to max in columns based on unique id column value in excel

This is given data in excel
I want it in this format
Arrange dates in min to max based on unique ids in excel.
EDIT
If you are using O365, then you may try using in this way as well,
Formula used in cell D2
=UNIQUE(A2:A10)
Formula used in cell E2
=TRANSPOSE(SORT(FILTER($B$2:$B$10,D2=$A$2:$A$10),,1))
For Excel Users 2007 & 2010 & onwards,
Formula used in cell D2 - To get UNIQUE id
=IFERROR(INDEX($A$2:$A$10,MATCH(0,COUNTIF($D$1:D1,$A$2:$A$10),0)),"")
Formula used in cell E2 --> To get sorted in ascending order dates based on ID,
=SMALL(IF($D2=$A$2:$A$10,$B$2:$B$10,""),COLUMN(A1))
Since its an array formula, you need to press CTRL SHIFT ENTER based on your excel version,
Or you may use this formula as well
=AGGREGATE(15,6,($B$2:$B$10)/($D2=$A$2:$A$10),COLUMN(A1))

In Excel, I want to compare each cell value with the rest of the cell values in that column

Here is the sample excel where i have bulk deals in stock market, i want to compare each stock and want to find whether it is a "Day Trade" or not.
Can you please suggest excel formula how can cell value with rest of the cell values in that column?
For example in the below example i have "Stock" column where i am trying to compare "Reliace" cell value with rest of the cell values in that column and updated "Result" as "Day Trade"
Create another sheet (e.g. Sheet2) and put "Reliance" and "HDFC" in A1:A2. Then in your table you can use the following formula:
=IF(NOT(ISERROR(MATCH(<StockName>,Sheet2!A1:A2,0))),"Day Trade","Not Day Trade")
Change with a reference to the cell with the stock name in. From your example it looks like this formula would go in cell D2 and StockName would be in B2
You can build this out, putting all of your day trade stock names in the lookup table on Sheet2, just update the reference in the formula

Excel Sum dynamic range

I would like to calculate the sum of a column total in a table, base on the name of the column header.
For example, below is a table of monthly sales by each person (from cell A4 to M7).
I would like to calculate the total monthly sales in Cell D13 with the month as an input variable (as in Cell B13).
My thought is =SUM(INDEX(B5:M7,MATCH(B13,B4:M4,0))) where I tried to use index and match function to find the range, then use sum function. It returns with an error and I am currently stuck here.
Your help is appreciated.
Using SUMPRODUCT function
In D13 enter formula :
=SUMPRODUCT((B4:M4=B13)*B5:M7)

Multiple criteria to sum a range of data

I'm using Excel 2013:
I calculated when income/expense would fall on a given date in the year: Budget sheet on top, Event Calc sheet on bottom
On my "Budget Adjust" sheet, I then wanted to sum the amounts with the criteria of: 1) within two dates and 2) matching the income/expense type:
While I now understand that I can't use SUMIFS (because my data to sum and date criteria are different sizes), I'm wondering if any of you have a brilliant idea about how to sum the data for specific date ranges and a type match.
ADDITIONAL INFO: Using the data in the first few columns, I created a dynamic formula for each day in the year, so columns T:NV, with a day of the year in Row 1:
=IF($D2<>0,IF(AND(U$1>=$C2,(U$1-$C2)/$D2=ROUND(((U$1-$C2)/$D2),0)),$B2,0),IF(DAY(U$1)=$E2,$B2,0)).
For that day of the year, for the type of income/expense, it would enter either the income/expense that would fall on that day, or zero. There are 365 such columns (T:NV), one for each year.
My attempt was to use the range of data (T2:NV20) in one formula on the Budget Adjust sheet that would search for: 1) within a given date rage, and 2) for each Type, then return the Sum of the amounts found within that date range
--- EDIT ---
I want an elegant answer, with one formula in the results field, but here's how I've made it work:
I'm limited to two pics per post, so here is a pic of both sheets:
My work-around to get the answer
On top is is the Event Calc page, where I've created a column for each month, and H2 is highlighted with the formula above:
=SUMIFS($U2:$NV2,$U$1:$NV$1,">="&H$1,$U$1:$NV$1,"<"&I$1)
On the bottom is the Budget sheet with D9 (Salary for Jan-2016) highlighted:
using this formula:
=SUMIFS('Event Calc'!H$2:H$20,'Event Calc'!$A$2:$A$20,"="&$B9)
Why wouldn't you just use 'Event Calc' columns A, B and C? That is already in a proper format for a SUMIFS formula. On sheet "Budget Adjust" cell D17, use this formula:
=SUMIFS('Event Calc'!$B:$B,'Event Calc'!$A:$A,$B17,'Event Calc'!$C:$C,">="&D$10,'Event Calc'!$C:$C,"<="&D$11)
and then copy right and down

Resources