I am trying to fill in my Summary Table with the data from a pivot table I have created. Within my summary table, I am trying to pull the closing number of the specified stock from the specific day. I believe the VLOOKUP function is the best way to do this, but I keep getting a #N/A. What is the proper way to write the VLOOKUP? My VLOOKUP Function looks like:
=VLOOKUP(C7,'Pivot Table'!$4:$3914,1,FALSE)
Do I need to restructure my pivot table or use an HLOOKUP?
You can use the MATCH() function in the VLOOKUP to find the correct column, but you need to look for the date first then the ticker column:
=VLOOKUP(E$6,'Pivot Table'!$5:$3914,MATCH($C7,'Pivot Table'!$4:$4,0),FALSE)
Then drag it over and down.
OR
If you want to look for the Ticker first you can use a HLOOKUP with a MATCH():
=HLOOKUP($C7,'Pivot Table'!$B:$N,MATCH(E$6,'Pivot Table'!A:A,0),FALSE)
OR
You can use INDEX() with two MATCH()
=INDEX('Pivot Table'!$A:$N,MATCH(E$6,'Pivot Table'!A:A,0),MATCH($C7,'Pivot Table'!$4:$4,0))
You may access the pivotCache directly:
Use the names of your pivot table fields either by :
1) Looking at the names of the fields in the field list
2) referring to your data table and seeing what names you use, or
3) using tabular or outline layout(instead of compact - and the field names wil come up in the rows and columns dropdowns).
Then use:
=GETPIVOTDATA("Close",'Pivot Table'!$A$4,"correctNameofDateField",E$6,"correctNameOfTickerField",$C7)
You can drag this across and down.
Related
I have below an example pivot table with Countries as my columns, and Dates as my rows. The data for this pivot is based on A1:C13. Cells F1:G3 is what the user of this model can adjust. They can change the country and/or the date ranges.
What I am needing is a single formula to output the total of their selection. As my actual data set contains many countries, simply writing an nested IF statement won't suffice. The dataset also needs to be in pivot table - hence the GETPIVOTDATA requirement.
I've gotten about half of the way there using this formula here:
=SUM(GETPIVOTDATA("Sum of Value",$A$15,"Date",ROW(INDIRECT(F2&":"&F3)),"Country",F1:G1))
The problem here is that this formula is not dynamic for the differing date selections per country.
Can anyone assist?
You need a separate GETPIVOTDATA for each country:
=SUM(GETPIVOTDATA("Sum of Value",$A$15,"Date",ROW(INDIRECT(F2&":"&F3)),"Country",F1),GETPIVOTDATA("Sum of Value",$A$15,"Date",ROW(INDIRECT(G2&":"&G3)),"Country",G1))
The answer provided by #basic is the closest one for the original question, i.e. using GETPIVOTDATA to work out the total per given parameters.
If the calculation can be done on the original data table (Range A1:C13), then here is another solution to calculate the total.
=SUMPRODUCT((A2:A13=F1:G1)*(B2:B13>=F2:G2)*(B2:B13<=F3:G3)*(C2:C13))
In order to make the above calculation "dynamic", i.e. the calculation updates as the rows expands in the table, you can put the source data into a Structured Reference Table, give a Name to each column, such as "List_Ctry" for Column A, "List_Date" for Column B, and "List_Value" for Column C, then the range behind each name will update automatically when the source data changes. Using these names, the formula will be something like:
=SUMPRODUCT((List_Ctry=F1:G1)*(List_Date>=F2:G2)*(List_Date<=F3:G3)*List_Value)
You can also give names to the three parameters, being the range of country, range of start date, and range of end date. I will not illustrate further as if you understand the above concepts, you should be able to do this step yourself.
By using Name in the excel workbook, it will enable you to refer to the source data conveniently without the need to lay it out in your final report, so I do not understand what is the limitation here to stop you from calculating from the source data but have to work on the pivot table, as the calculations on pivot table are limited and not that intuitive.
Feel free to let me know if you have any questions :)
I'd like to perform the standard deviation of a specific range in a pivot table.
I tried the following formula to get the SD of the range C8:C28:
=STDEV(GETPIVOTDATA("Sum of PL DIR & CAR",$A$4,"AssetClass2","Equity US"))
It returns #DIV/0!
Do you have the correct formula?
Here is the pivot table:
Based on your image, you might be able to use something like the below, assuming there is no data below the pivot table
This will work even if additional rows are added into the pivot, i.e making it a dynamic range with OFFSET etc.
=STDEV(OFFSET($C$8,0,0,COUNTA($C:$C)-2,1))
Or you can use INDEX which is a non-volatile function:
=STDEV(INDEX($C:$C,ROW(C8)):INDEX($C:$C,COUNTA($C:$C)+1))
You may need to tweak that COUNTA($C:$C)+1 to fit your criteria but this should give you the idea.
how can i set condition inside pivot sum data to refer label row ?
I need to sum data only if row label is equal to specific value.
I'm trying to use standard IF but it doesn't work.
Thanks.
Use a vlookup ( within a vlookup.? Others please say if that is necc). copy paste your row tabels in another column in another sheet/tab and look for them im ur pivot.
Vlookup(a1,sheet2(column),1,0).
Altetnatively u culd just copy paste text only the pivot table results, and use ur if statement there.
But vlookups are superior if statements. So us that is more dynamic/poweful.
I would use a sumproduct function if I were you.
https://www.ablebits.com/office-addins-blog/2016/08/24/excel-sumproduct-function-formula-examples/#Conditionally
To sum Apples sales for North:
=SUMPRODUCT(--(A2:A12="north"), --(B2:B12="apples"), C2:C12)
I want to use several GetPivotData functions, retrieving data from the same Pivot table. I want each of them to retrieve different data based on a filter value.
For instance:
Get Pivot Data for Month:January
Get Pivot Data for Month:February
Where Month is a filter on the Pivot. Is this possible using a formula?
I hope this will solve your problem. Try this workaround from Microsoft:
https://support.microsoft.com/en-us/help/287736/getpivotdata-formula-is-automatically-created-when-you-try-to-create-s
When you change the month, the value changes too. But make sure that there are no hidden items (because if not, you won't get an accurate #/data).
see the screenshot below where the Month to choose is based on a cell reference as an argument in the GETPIVOTDATA formula:
Victor,
The Pivot tables won't work like you intend to. All data that your formula shall retrieve must be visible at the same time. I suggest that you arrange for some space on your worksheet and apply the solution proposed by Scott.
NB: If you want to deal with data added month by month, for example, there is an Pivot table option to automatically add new values to the filter. Then in your formula you can use IFERROR to show blank cells when there is still no data available.
Regards,
+Daniel+
I have an Excel Table named Table5 which consist of two columns CompanyCode and EmployeeLevel. Now my question is i want to get the unique values of EmployeeLevel columns. Take note that the length of the record is unknown. I am using the Table5[EmployeeLevel] as the range to include all the records in the Table5. Is there a formula that you can provide ? I cannot use ActiveX object to loop through each record. I must do it via Excel formula. The solutions I got are only usable when it is fixed how long the records are. but this record I am working on is a dynamic table.
Thanks in advance :)
Assuming your data looks like this:
The easiest way to do this is to create a Pivot Table based on Table5. In the Rows, add EmployeeLevel. In Data, add EmployeeLevel.
Change the data aggregation to Count rather than sum. You will get something like this.
When you add a new item to Table5, all you need to do is update the PivotTable (right-click on the PivotTable and click update).
If you need to use formulas, the following is a workaround.
In Column C, add the following formula (given the below data, adjust to fit):
=--(COUNTIF($B$1:$B2,$B2)=1)
This will return a 1 for every unique value in the table.
Somewhere on the sheet (in my case F2), I added the following formula to count unique values:
=SUM(Table5[Unique Value])
In my sample data, there are 14.
I then copied the following formula from F3 down 20 rows (I used 20 because I don't have that many unique values -- you say your table is variable, so pick a number of rows higher than the amount of unique values you expect in the future):
{=IF(ROW(A1)<=F$2,SMALL(IF(Table5[Unique Value]=1,Table5[EmployeeLevel]),ROW(A1)),"")}
Note -- the curly braces are an array formula -- do not add them by hand, enter the formula without them and confirm with ctrl+shift+enter
This will result in the unique values in ascending order:
You might be able to achieve the count from within the table itself, provided EmployeeLevel is sorted: