Use dynamic sum range and criteria range in SUMIFS - excel

I'm using SUMIFS to calculate sales revenue of product X over a period of time. The problem is that all the sum range and the criteria ranges are dynamic since sales reps will add more rows to record new sales everyday. My formula looks like this:
=SUMIFS(Revenue!I5:I24,Revenue!F5:F24,"Product X",Revenue!B5:B24,">="&B3,Revenue!B5:B24,"<="&C3)
The starting row is row 5, and the last row that currently has data is row 24.
Revenue is the worksheet that contains the data. In this worksheet, column I is the revenue, column F is the product name, column B is the date that the revenue is recorded. B3 and C3 are the start and end date of the period.
When a sales rep records a new revenue, the last row that has data will become row 25, so my formula won't count it in. I tried to replaced 24 with 1000 hoping that it would count when new data was added beneath, but it returned #VALUE.
What should I do?
Thank you

Declare 3 dynamic ranges and use their names in your formula.
=IFERROR(SUMIFS(revenueI,revenueF,"Product X",revenueB,">="&B3,revenueB,"<="&C3),"")
Adding the names: Press Ctrl+F3 to open the name manager and then enter the 3 names
Name: revenueB
RefersTo=
OFFSET(Revenue!$B$5,0,0,COUNTA(Revenue!$B$5:$B$1048576),1)
Name: revenueF
RefersTo=
=OFFSET(Revenue!$F$5,0,0,COUNTA(Revenue!$F$5:$F$1048576),1)
Name: revenueI
RefersTo=
=OFFSET(Revenue!$I$5,0,0,COUNTA(Revenue!$I$5:$I$1048576),1)
1048576 is for the max number of rows in more recent versions of Excel. Adjust to the total number of rows for your Excel version.
Wrap in an IFERROR in case of errors e.g. if named ranges are off different length.

Related

How can I average the last n number of rows when using a Average(Index, match formula)?

I have two sheets one has a table with sets across the top of the table and daily km for each set the second sheet has set numbers in column b, I wish to find the daily average for the last 6 months (so 182 days) for each of the sets and return the value in column F.
Sheet 2
sheet 1 - Table
I have used the following formula to average the entire column
=AVERAGE(INDEX(Table1[[H9003]:[H9043]],0,MATCH('FA Forecasts'!B5,Table1[[#Headers],[H9003]:[H9043]],0)))
However I only want to return the average of the last 182 rows of the table to the corresponding set number - and each time a new line is added I only want the last 182 rows.
I'm not sure what I can do to achieve this - any advice would be most appreciated.
If you have Excel 365 you can use this formula:
=LET(indexSetNumber,MATCH([#[Set Number]],tblSheet1[#Headers],0),
filterByDate,FILTER(tblSheet1,tblSheet1[Date]>=LARGE(tblSheet1[Date],cntDays)),
filterBySet,INDEX(filterByDate,,indexSetNumber),
AVERAGE(filterBySet))
I like "readable" formulas - this one reads like this:
indexSetNumber: returns the column index of e.g. H9003 --> 5
filterByDate: returns the rows with Top "cntDays" dates. I am using a parameter cntDays in C2 - for this example I chose 2, but you would put 182.
filterBySet: returns column indexSetNumber from filterByDate
from these values AVERAGE is returned.
This might also work (assuming C2 is =TODAY()):
=AVERAGEIF(Table1[Date],">" & C2 - F2,INDIRECT("Table1["& 'FA Forecasts'!B5 &"]"))
Using AVERAGEIF formula :
Table1[Date] : returns the "Date" table column (sheet 1)
">" & C2 - F2 : "date more recent than Today-182 days"
INDIRECT("Table1["& 'FA Forecasts'!B5 &"]") : returns the table column (sheet 1) which header match with Set Number in the current row (sheet 2)
Basically return the average for kms in the past 182 days for the Set Number of the row.

Countif formula with multiple criteria

In my workbook, I have a 4 spreadsheets - Data, Amy, Betty, Connie. Data has the following columns:
Column A Column B Column C Column D
Row 3 Employee Total tasks last 30 days. Total tasks last 7 days. Date/Time Last task Assigned
Row 4 Amy
Row 5 Betty
Row 6 Connie
In A1 - worker with oldest task Date/Time Assigned. Cell B1 contains the answer to cell A1 by providing the employees name.
I enter the data in the individual workers spreadsheets (Amy, Betty, Connie) and my Data worksheet provides the summary. On my data worksheet, I have formulas that count the number of tasks within the last 7 days and last 30 days by using the date/time assigned column (Column E)in the individual worksheets. Currently, if someone is out of the office, on their individual worksheet, I enter OUT in the task column (Column B) and the date/time that they will return in the date/time assigned column (Column E)so it will skip them for B1 on my Data worksheet. I need a formula that would not count the date/time assigned if they were OUT as a task, when calculating in columns B and C in the data worksheet.
Here is the formula that I have currently for Column B (total tasks last 30 days)
{=COUNTIF(INDIRECT("'"&A4&"'!"&"E1:E1000"),">="&(NOW()-30))}
The formula that I have for cell B1 is:
{=INDEX(A4:A14,MATCH(MIN(E4:E14),E4:E14,0))}
Any help would greatly be appreciated.
I figured it out:
=COUNTIFS(Amy!E2:E1000,">="&(NOW()-30),Amy!A2:A1000,"<>out")
Like suggested in the comments, the COUNTIFS formula is what you want to use. Information about its usage can be found here.
Adding the condition for excluding the "OUT" values would make the formula look like this:
=COUNTIFS(INDIRECT(""&A4&"!"&"E1:E1000"),">="&(NOW()-30),INDIRECT(""&A4&"!"&"B1:B1000"),"<>OUT")

Excel: Match\Index specific column based on multiple criteria

I have two Tables, Table 1 Column A is a rolling date column. Table 2 consists of four columns of differing "Trigger Dates". Table 2, Column 1 contains an Annual trigger, ie occurs once a year. Table 2 Column 2 contains Bi-Annual Triggers, and occurs twice yearly. Table 2 Column 3 contains Monthly Triggers, "12 dates" and Table 2 Column 4 contains Weekly Triggers, "52 dates".
Ok, so what I'm looking for is to a formula that will return the date trigger, where Table 1 Column 1 matches a condition (Annually, Bi-Annually, Monthly, Weekly) selected in a cell "we'll say F1, outside of any ranges that may be created.
Example: If Table 1 Col 2 = "01/02/2013" and I select "Weekly" in F1, the formula will look in the weekly Column in Table 2 to determine if "01/02/2013" exists.
I've allocated a named range to each column in Table 2
I've allocated a named range to the condition in F1 which is a drop down list
Any suggestions?
You might try:
=IFERROR(VLOOKUP(B2,INDIRECT(CHAR(72+MATCH(F$1,$I$1:$L$1,0))&":"&CHAR(72+MATCH(F$1,$I$1:$L$1,0))),1,0),"")
Ok, so supposing your Range Name is in F1, your formula to find the match would look as follows:
=If(IsError(Match(LookupVal,Indirect(F1),0)),"No Match", "Match")
...Something along those lines
Hope this helps point you in the right direction.
INDIRECT and VLOOKUP will be your friends here.
I constructed Table2 just as you had described, with the Annual,Bi-annual,Monthly,Weekly labels for the columns in the table - this will avoid having to keep named ranges up to date, as it's looking directly at the table in the formula
For the function, I then used VLOOKUP to find the date, in the column referenced by F1.
Column Reference: INDIRECT("Table2["&$F$1&"]")
Find Value: VLOOKUP([#Col2],INDIRECT("Table2["&$F$1&"]"),1,FALSE) (looking at column 1 in the return values, as I don't really care what value is returned.
This will return the date if found, and an error if not. I can then wrap the result in the IF(ISERROR( so I can return Yes or No if the date is found.
This produces the entire formula of
=IF(ISERROR(VLOOKUP([#Col2],INDIRECT("Table2["&$F$1&"]"),1,FALSE)),"No","Yes")
for the next column in Table1, so that when I change the value in F1, it will look for that column name in Table2, and let me know if it is found.

How do I check for duplicate rows and do calculate on that rows in excel file?

I have one excel file which is having data like following
CUSIP Quantity Date Price
AF0 500000 5/6/2013 1
AE4 400000 5/6/2013 1.0825
AE4 500 5/6/2013 1
I need to check for column CUSIP and Date
If I'm having duplicate CUSIP for same date then I need to do following calculation.
1.Need to add Quantity for both of them instead of showing duplicate records need to show only one record( sum of Quantity).
2.Need to do calculation on Price as well like following
NewPrice = ((400000 * 1.0825) + (500 * 1.00))/(400000 + 500) = 1.08148
For example in using above data
Need to show output like
CUSIP Quantity Date Price
AF0 500000 5/6/2013 1
AE4 400500 5/6/2013 1.082397004
How do I achieve this in excel file using LOOKUP or else ?
Okay, after quite some research (interesting question by the way!), I came up with this:
=IF(COUNTIF($A$2:A2,A2)>1,"",SUMIF(A:A,A2,B:B))
=IF(COUNTIF($A$2:A2,A2)>1,"",SUMPRODUCT(--(A:A=A2),B:B,D:D)/SUMIF(A:A,A2,B:B))
Put these in cell D2 and E2 respectively (which is the next column after Price and in the row of CUSIP AF0).
And fill to the bottom of the worksheet to get the weighted average price or each CUSIP.
The first formula gives you the total quantity for the CUSIP and the second gives you the average price.
Copy and paste values for those two columns after calculation.
Put a filter and remove all the rows where the total quantity and average price is blank, and sort to make the worksheet neat.
Let me know if this works for you! I tried it on your sample data and it seems to be working. It's my first time using SUMPRODUCT ^^;
SUMPRODUCT(--(A:A=A2)
This bit returns the rows from column A where it equals to the row's CUSIP.
SUMPRODUCT(--(A:A=A2),B:B,D:D
This additional bit tells excel to multiply the values in column B and D of each returned row found above and SUMPRODUCT adds each result together.
EDIT:
I actually forgot about the date. You could maybe add a helper column where you'll generate an identifier to separate the different dates. To make it, you'll have to make a concatenate.
Hence in cell F2, you put:
=CONCATENATE(A2,C2)
In the formulae for cells D2 and E2, you will have to change them so they become:
=IF(COUNTIF($F$2:F2,F2)>1,"",SUMIF(A:A,A2,B:B))
=IF(COUNTIF($F$2:F2,F2)>1,"",SUMPRODUCT(--(A:A=A2),B:B,D:D)/SUMIF(A:A,A2,B:B))
reEDIT: Oops, put the wrong reference. Fixed now.

Excel lookup vector based on another formula

My spreadsheet has 2 sheets.
Sheet 1 contains 30 days worth of values.
Each day's values are a maximum of 19 rows, consisting of names and correspoding values. The names that will appear for each day are not the same every day. In other words my name might appear on the 1st, 2nd and 14th of the month and not on any other days. (And these values may not be sorted.)
My second sheet will display only one persons values for the month, and I therefore use a lookup.
The formula for the 1st day is:
=LOOKUP("name";'Input Sheet'!$A$2:$A$20; 'Input Sheet'!B2:B20)
For the second day it would be:
=LOOKUP("name";'Input Sheet'!$A$22:$A$40; 'Input Sheet'!B22:B40)
The only thing that changes for each day is the lookup range/vector. I have a separate (hidden) column already that has calculated the correct starting row number, i.e. 22, 42, 62, but how would I use that number to change the lookup range on my formula?
Thanks a lot
Michael
The indirect() function will allow you to specify the range for your lookup in terms of another cell.
For example, if Sheet1 of the workbook has the numbers 1-10 going from A3:A12, where the starting row (3) is specified in cell B1 of the same worksheet.
3
1
2
3
4
5
6
7
8
9
10
Then to lookup the value 5 and place the answer on any other sheet of the workbook:
=LOOKUP(5,INDIRECT("Sheet1!$A"&Sheet1!$B$1&":$A$12"))

Resources