Referencing a vlookup result as a formula argument - excel

Suppose the value of cell A1 is total sales $ at the Los Angeles location, year to date. The value is pulled from a pivot table on a different sheet.
The formula for A1 is:
=SUM(GETPIVOTDATA("Amount",'Transactions(Pivot)'!$A$75,"Location","Los Angeles","Months",{7,8,9,10,11,12}))
Currently, every month when I run this report I need to manually update the month arrays in the formulas; for example next month I will need to manually update {7,8,9,10,11,12} to {7,8,9,10,11,12,1}. There are many cells and this is a very tedious task.
My question is how can I automate the task of updating the month array in the GETPIVOTTABLE formula?
What I've attempted with no success: I set up a 2-column lookup table on a different sheet where column A is the current month and column B contains the month array value to be used in the GETPIVOTTABLE formula. For example:
7 {7}
8 {7,8}
9 {7,8,9}
etc...
Then I tried updating my GETPIVOTTABLE formula to use a VLOOKUP to get the month array:
=SUM(GETPIVOTDATA("Amount",'Transactions(Pivot)'!$A$75,"Location","Los Angeles","Months",VLOOKUP($B$2,$L$9:$M$20,2,FALSE))
But it didn't work - I get a #REF! error.
Thanks in advance for your help.

You can give a range instead of the vlookup and enter the numbers 7,8,9 . . . . in that range for example your formula
=SUM(GETPIVOTDATA("Amount",'Transactions(Pivot)'!$A$75,"Location","Los Angeles","Months",{7,8,9,10,11,12}))
will become
=SUM(GETPIVOTDATA("Amount",'Transactions(Pivot)'!$A$75,"Location","Los Angeles","Months",A1:A7))
and A1 to A7 contains the months.
after entering this formula press Ctrl+Shift+Enter

Related

Excel, how to Sum on Column based on if the dates in another Column match the current month?

I need to find the sum of the cells in a Column if their end dates in another column occur in the current month.
I tried using the formula =sumif(L:L,MONTH(TODAY()),J:J) but it doesn't work.
Column L contains the full date (ex: 12/1/18).
Column J contains the values I want to add up.
So since it's December, I want to add all the values in J that have a date that is in December, and so on a so forth when I use the sheet in January.
Try this formula:
=SUM(IF(MONTH(L:L)=MONTH(TODAY()),J:J,0))
and enter it with Ctrl-Shift-Enter as it is an array formula.
Or use =SUMPRODUCT((J:J)*(MONTH(L:L)=MONTH(TODAY())))

Excel - listing data from all rows that fall between two dates, while ignoring blank entries

I can't get my head around the formula required to return a list of data from all rows in excel that fall between two specific dates.
Sheet1 contains the following data:
Date Region Reference
01/01/2015 B 4458
01/02/2015 B 6635
01/02/2016 A 3175
01/03/2016 C 2458
01/03/2016 A 2194
01/04/2016 A 3594
01/04/2016 C
01/05/2016 C 1654
12/05/2016 B 3648
01/06/2016 B
01/06/2016 B 3296
In Sheet2, I specify a start date in cell C2 and an end date in cell C3.
I would like to display a list in sheet2 that gives me a list of all reference numbers in sheet1 that fall within that date range. I will also however want it to ignore any cells that are blank and do not contain a reference number.
I've tried a few things to get this working, and I think an array formula using an INDEX function is probably the best bet, but I'm struggling to get the date range aspect to work.
Is anybody able to help please?
Thanks
I would advise that you format your data as a table if you haven't already as it makes the index function much easier to read.
The formula below should do what you require. The * in the if statement is like an "and". -4 near the end of the formula is the number of rows betwen the source table and the top of the sheet it's on. The last 1 at the end of the formula is the column that you want to take data from much like you have in a vlookup. remember to use SHIFT+CTRL+ENTER to make it an array formula.
=IFERROR(INDEX(Table1,SMALL(IF((Table1[Date]>=$C$2)*(Table1[Date]<=$C$3)*(Table1[Reference]<>""),ROW(Table1)-4),ROW(1:1)),1),"")
Formula if you don't want to format as table
=IFERROR(INDEX(Sheet2!$C$5:$E$15,SMALL(IF((Sheet2!$C$5:$C$15>=$C$2)*(Sheet2!$C$5:$C$15<=$C$3)*(Sheet2!$E$5:$E$15<>""),ROW(Sheet2!$C$5:$E$15)-4),ROW(1:1)),1),"")
Using the formula
I't not advisible to copy and paste this formula from one cell to another but instead copy the formula text and paste it to avoid parts of the formula changing.
keep an eye on the ROW(1:1) at the end of the formula, it specifies which row from the matching results will be extracted from the data and it should increment when you autofill the formula down the sheet.

VLOOKUP on a date returning REF error

I have a list of dates in a sheet (called TABLE) with the corresponding fiscal week next to the date.
On another sheet (ORDERS), I am trying to Lookup the date in the TABLE sheet and pull the corresponding week # in.
Here is my formula:
=VLOOKUP(J4,TABLE!A:A,2,FALSE)
where J4 is the date in the ORDERS sheet, A:A has the dates listed and column B on TABLE has the week #.
I get a REF error... It seems like it tries to convert the date from "5/23/16" to "42513" for whatever reason. Help!
The #REF error occurs because you have not selected enough columns. If you change your formula to =VLOOKUP(J4,TABLE!A:B,2,FALSE) it should work fine.

How to retrieve specific information from a column and show its number of occurrences

I have a column which contains dates. I want to search this column and find the total entries for each month, and summarize the sum in a nice display. Example:
I want to display the number of times 'Disposition Verification Dates' occur in each month and summarize ("count") them in a format which follows:
I want to make several rows with the same concept in the same table for my other columns.
How do I do this? (PivotTables, VBA, IF statements?)
I would suggest adding a helper column which you can hide. See the formula in cell C1.
For the January column I used the following formula:
=COUNTIF($C$1:$C$7, 1)
February is:
=COUNTIF($C$1:$C$7, 2)
and so on. You can also use the YEAR function and convert the countif into a COUNTIFS function based on the other year helper column.
No VBA needed. No helper column needed. No Pivot Table needed.
In addition to Yaegz provided, and my comments, you can use an array formula.
Assuming your data is column A and you type Jan Feb Mar ... Dec into cells B1:N1, you can enter the following formula in cell B2.
=COUNT(IF(TEXT($A$2:$A$13,"mmm")=B$1,$A$2:$A$13))
Then press Ctrl + Shift + Enter (to make it work as an array) and you will have your summary done.

Count number of occurrences by month

I am creating a spreadsheet with all my data on one sheet and metrics on the other.
On sheet 1 in cells A2:A50 I have the dates in this format (4/5/13). On sheet 2 in cell E5 I have April and I want it to total the number of PO's created in F5.
How can I do this?
I have tried using
=COUNTIF('2013'!$A$2:$A$50,'2013 Metrics'!E5).
I have a feeling that since my range is in 4/5/13 format and my criteria is April that won't work.
I was able to use this formula for total spend by month:
=SUM(IF(MONTH('2013'!$A$2:$A$19)=4,'2013'!$D$2:$D$19,0))
but not luck with how many PO's by month.
Use a pivot table. You can manually refresh a pivot table's data source by right-clicking on it and clicking refresh. Otherwise you can set up a worksheet_change macro - or just a refresh button. Pivot Table tutorial is here: http://chandoo.org/wp/2009/08/19/excel-pivot-tables-tutorial/
1) Create a Month column from your Date column (e.g. =TEXT(B2,"MMM") )
2) Create a Year column from your Date column (e.g. =TEXT(B2,"YYYY") )
3) Add a Count column, with "1" for each value
4) Create a Pivot table with the fields, Count, Month and Year
5) Drag the Year and Month fields into Row Labels. Ensure that Year is above month so your Pivot table first groups by year, then by month
6) Drag the Count field into Values to create a Count of Count
There are better tutorials I'm sure just google/bing "pivot table tutorial".
For anyone finding this post through Google (as I did) here's the correct formula for cell F5 in the above example:
=SUMPRODUCT((MONTH(Sheet1!$A$1:$A$50)=MONTH(DATEVALUE(E5&" 1")))*(Sheet1!$A$1:$A$50<>""))
Formula assumes a list of dates in Sheet1!A1:A50 and a month name or abbr ("April" or "Apr") in cell E5.
Make column B in sheet1 the dates but where the day of the month is always the first day of the month, e.g. in B2 put =DATE(YEAR(A2),MONTH(A2),1). Then make E5 on sheet 2 contain the first date of the month you need, e.g. Date(2013,4,1). After that, putting in F5 COUNTIF(Sheet1!B2:B50, E5) will give you the count for the month specified in E5.
I would add another column on the data sheet with equation =month(A2), then run the countif on that column... If you still wanted to use text month('APRIL'), you would need a lookup table to reference the name to the month number. Otherwise, just use 4 instead of April on your metric sheet.
use count instead of sum in your original formula u will get your result
Original One
=SUM(IF(MONTH('2013'!$A$2:$A$19)=4,'2013'!$D$2:$D$19,0))
Modified One
=COUNT(IF(MONTH('2013'!$A$2:$A$19)=4,'2013'!$D$2:$D$19,0))
AND USE ctrl+shift+enter TO EXECUTE
Recommend you use FREQUENCY rather than using COUNTIF.
In your front sheet; enter 01/04/2014 into E5, 01/05/2014 into E6 etc.
Select the range of adjacent cells you want to populate. Enter:
=FREQUENCY(2013!!$A$2:$A$50,'2013 Metrics'!E5:EN)
(where N is the final row reference in your range)
Hit Ctrl + Shift + Enter
Sooooo, I had this same question. here's my answer: COUNTIFS(sheet1!$A:$A,">="&D1,sheet1!$A:$A,"<="&D2)
you don't need to specify A2:A50, unless there are dates beyond row 50 that you wish to exclude. this is cleaner in the sense that you don't have to go back and adjust the rows as more PO data comes in on sheet1.
also, the reference to D1 and D2 are start and end dates (respectively) for each month. On sheet2, you could have a hidden column that translates April to 4/1/2014, May into 5/1/2014, etc. THen, D1 would reference the cell that contains 4/1/2014, and D2 would reference the cell that contains 5/1/2014.
if you want to sum, it works the same way, except that the first argument is the sum array (column or row) and then the rest of the ranges/arrays and arguments are the same as the countifs formula.
btw-this works in excel AND google sheets. cheers

Resources