Excel function array formula based on sumif to find minimum count - arrays

I have some data where I want to find the minimum number of days it takes to reach a total sum based on some criteria.
Essentially the data is like this:
Date Season Recieval
1/01/2006 2006 500
2/01/2006 2006 100
3/01/2006 2006 150
…
10/12/2009 2009 300
etc
Want I want to do is find a formula that finds the minimum number of days it takes to reach a receivals total for the season.
The formula below is what I have tried so far with no avail.
=MIN(COUNT(IF(SUMIFS(C:C,B:B,"2006")>2000,DATA!A:A)))
It doesn't matter what point it starts from, but it must take the minimum number of days to reach the 2000.
Output should be a number eg 39 (39 days consecutive to sum up to receivals of 2000).
Essentially what I want to generate is the minimum number of consecutive days required to reach the total of 2000, regardless of the starting point.
Cheers!

If your Dates are in the range A2:A25 and Recieval in C2:C25, then try this...
=INDEX(A2:A25,MATCH(TRUE,INDEX(SUBTOTAL(9,(OFFSET(C$2:C25,,,ROW(INDIRECT("1:25")),1)))>=2000,),0))-A2
The formula will get you the no. of days to reach total 2000 receival in column C.
Or if you just need to count the consecutive dates, please try..
=MATCH(TRUE,INDEX(SUBTOTAL(9,(OFFSET(C$2:C25,,,ROW(INDIRECT("1:25")),1)))>=2000,),0)
Remember both the formulas are Array Formulas which require a special key stroke Ctrl+Shift+Enter instead of Enter alone.

Related

Pivot table - Display growth rate with calculated field in Google Sheets

I'm trying to create a calculated field that displays the growth rate in % from one of the numeric columns in my pivot table.
How can I reference a row above the current cell to calculate the growth rate?
=(Current cell - (Current cell - 1 Row)) / (Current cell - 1 Row)
Pivot table
Year
Count
Calculated Field (YoY Growth)
2019
100
2020
300
100%
2021
600
50%
based on instructions:
=(Current cell - (Current cell - 1 Row)) / Current cell
={""; ARRAYFORMULA(IFERROR(B2:B-(B2:B-B1:B999)/B2:B))}
I agree with player0, that seeing your sheet, data, data types and layout would facilitate helping you.
However, I'll venture a solution, sight unseen.
There are actually many ways to address what I think you're asking. This is just one of them.
Suppose that your source numbers are in range A2:A. Place the following formula in some other open column, in the cell parallel to the top number in your source range:
=ArrayFormula(ARRAY_CONSTRAIN({"";FILTER(({A3:A;""}-A2:A)/{A3:A;""},A2:A<>"")},COUNTA(A2:A),1))
I've added in more "parts" than are probably necessary. But I tried to include controls, seeing as I don't know what your data actually looks like.
An alternative is to place the following simpler formula into the cell one below where the top number in your source range is:
=ArrayFormula(IF(A3:A="",,(A3:A - A2:A)/A3:A))
In either case, you'll want to format the column/range where the results will be as percent (Format > Number > Percent).
Obviously, if your source numbers are in a range other than A2:A, you'll need to adjust the ranges in either formula accordingly.

Comparing two dates in array based on criteria in Excel

I am trying to find a formula which will compare two dates (Plan 1 minus Plan 2) and determine if they are within ninety days of each other.
The formula I have so far:
{=IF(E1<>"", IF(AND(MIN(IF(C:C=C1, IFERROR(E1-G1, -2), 0))<91, MIN(IF(C:C=C1, IFERROR(E1-G1, -2), 0))>-1), 1, 0), 0)}
The idea is that the array will loop though the Subjects in Column C and for every subject with a non-blank Plan 1 field (Column E), it will loop through the Plan 2 dates in Column G to find the closest one within ninety days. If one exists, the equation will give the Plan 1 a 1.
However, the formula above is not able to handle the dates seen below where there is no exact matching date in Column G.
Thank you for your help.
Scott Craner found the delightful equation below to answer this problem, except for the issue in the image below. It appears to be including a date greater than 90 days (orange highlight).
Use AGGREGATE:
=IF(E2<>"",IFERROR(--(AGGREGATE(15,7,(E2-$G$2:$G$21)/(($C$2:$C$21=C2)*(E2-$G$2:$G$21>=0)),1)<91),0),0)

Dynamic Columns in SSRS with Dynamic Row Summing?

So I've got a pretty simple view that looks like this:
Location Month DelRec Warehouse_Number Code Value
Canada November Deliveries Warehouse1 C 11041.2
Canada November Deliveries Warehouse 2 C 0
Canada November Receipts Warehouse 3 C 0
USA November Receipts Warehouse_10 H 2543.2
Ultimately, what I would like to create is a matrix in SSRS that uses 'Code' as a dynamic column name and grouping by DelRec and Location (expanding the number of columns for each code available for that grouping). Easy enough, right? Looks something like this:
Now the next step I've got is to do some conditional summing on these values, which has got me stymied. In particular, for example, in the below data, for Canada, Deliveries need to be summed up together (Warehouse 1 and 2), and then the total of those two subtracted from Receipts (in this case, just Warehouse 3). Ostensibly, this would look something like this:
The problem is, I can't figure out how to do conditional summing (i.e. sum deliveries and subtract them from the sum of receipts), especially when dynamic columns are involved (because we don't know what warehouse numbers might come in future data).
In addition, I actually need a column that has the Total Deliveries and Total Receipts, which is causing me even further difficulty.
Anybody have any idea of how to do this? The result should look something like this:
I've created a a pastebin
with some representative SQL data for insert if anyone would actually like to try this out.
As I understand essentially "Receipts" are credits and can be treated as a positive amount and "Deliveries" are debits and can be treated as a negative amount. To get the correct total you could replace the Sum expression in the bottom right of the matrix with
=Sum(IIF(Fields!DelRec.Value="Receipts",Fields!Value.Value,-1 * Fields!Value.Value))
To get a total line for deliveries and receipts you need to either right click on Warehouse_Number in the matrix, then click on Add Total then click on After.
Alteratively you can right click on Warehouse_Number in the Row Groups and add total from there.
The matrix should now look like this
The report should now look like this
Right clicking on Code in the matrix then "Add Total" -> "After" will add Row Totals as a new column. Note that this will only total "Receipt" or "Deliveries" by Location as the report is grouped Location then DelRec then Warehouse. You could achieve a Receipt Grand Total through either adding extra rows at the bottom of the matrix, or better in my opinion is another table only grouped by DelRec to calculate the DelRec Grand Totals.

Multiplying arrays resulting from multiplying arrays in Excel

I've tried looking through some of the posts and I'm having trouble finding something that will help me in this situation.
I have a spreadsheet that has Total Sales, Retail Price, and Inventory for each week in a year for a list of 100 or so projects. These three pieces of info are displayed as columns repeated for the year, with a row for each item.
I was able to add up the total annual cells (every 3rd column) using SUMPRODUCT((MOD(COLUMN(D3:L3),3)=0)*D3:L3)
The next goal is to get a formula to calculate the weighted average retail. I basically need to find a formula that will end up with the SUMPRODUCT of an array of Sales data and Retail data.
I have tried to use some layering of MMULT and SUMPRODUCT but keep getting #VALUE! errors. Particularly with SUMPRODUCT(TRANSPOSE(MMULT(TRANSPOSE((MOD(COLUMN(D3,L3),3)=0)),D3,L3)),MMULT(TRANSPOSE((MOD(COLUMN(D3,L3),3)=1)),D3,L3)) and with putting braces in there as well =SUMPRODUCT({TRANSPOSE(MMULT(TRANSPOSE((MOD(COLUMN(D3,L3),3)=0)),D3,L3))},{MMULT(TRANSPOSE((MOD(COLUMN(D3,L3),3)=1)),D3,L3)})
Does anyone have any experience with this type of issue? I feel like it should be something that Excel can do without having to have separate sheets to calculate.
For your weighted average:
=SUMPRODUCT(($D$2:$FD$2="Sales")*$D3:$FD3*$E3:$FE3)/SUMIF($D$2:$FD$2,"Sales",$D3:$FD3)
And also, to add up the Sales, you could consider:
=SUMIF($D$2:$FD$2,"Sales",$D3:$FD3)
I am assuming FD is the last column of data for the year, but change it if that is not the case.

Rolling Arrays as a possible solution to a rolling window in SAS

I am trying to calculate the dosage of a particular drug for a population to see if any member in this population is over a certain threshold for any 90 consecutive days. So to do this I am thinking that I am going to need to make a arraty that looks at the strengh of this drug over 90 days from an index and if they are all '1' then they get a 'pass', and somehow put this into a do loop to look at all of the potential 90 day windows for a year i=1...i=275 to see if a member at any point during the year has met the criteria. Thoughts?

Resources