Formula to reference data from a PivotTable - excel

I am having some difficulty writing a specific Excel formula. I have a summary sheet that pulls data from various other sheets extracted from a database. One of these is a PivotTable whereby using the Item Number in the first column and the dates along the top row as a reference I can pinpoint the data I need. eg:
To address the highlighted cell I would normally manually write:
=GETPIVOTDATA(HighPiv,"SPN010977-204 11333")
HighPiv is the name I gave to the pivot table as I am referring to it from my summary sheet.
This works, however the Week numbers along the top will continuously be changing in the pivot every month and therefore this formula will not pick up the values accurately once the pivot is updated. I have been looking into a way to make the referencing more dynamic. This is the summary where the data is required:
Rather than within the quotation marks of the formula (adding the specific Item number and Week number word for word), I was hoping to refer to the cell references of the summary sheet. (So if I wanted Item number, say A55, and Week number, say H50). The dates in the summary sheet change according to the pivot so referring to the dates on the summaries to get the data would be a better way for it to be kept up-to-date.
The problem here is I don't know how to go about it. I have tired to refer to the cells in question but it doesn't seem to work giving me #REF! or #VALUE! errors.

I think what you would like is:
=GETPIVOTDATA("Qty",HighPiv,"Item",A55,"Week",H50)
I find the easiest way to write such a formula is to start by ensuring that Pivot Table Tools > Options > PivotTable – Options, Generate GetPivotData is checked then in the desired cell enter = and select the required entry from the PT (here63). That would show (for example) “SPN010977-204” and 11333 or ”11333” but these can be changed to A55 and H50.

Related

Dynamic GETPIVOTDATA formula to SUM with different date ranges per column

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 :)

How to count unique column data in an excel sheet

I am using excel sheet and i have data column as shown below:
As we can see that some of the names are duplicate or appeared twice. My question is how can count unique name records or rows associated with each name for summary column.
Out put i am looking for is shown below:
Not sure which formula to use as count is counting all of that data i.e. '7' in this case. How can i use count or any other function to count unique records as shown above?
You can do what you're after with a pivot table.
Click the Insert tab then select "Recommended Pivot Tables".
A window will open up prompting you to select the data range. I recommend using a named range for your list and referencing that, but you can just highlight the list directly if you want.
Once the data range is selected, click "Ok" and new window will open with exactly what you want. A unique values list and a "Count of Column1". It is the default of the recommended pivot tables.
I outlined this because it's easy and fast, but it's important to understand you can make this pivot table yourself from scratch if you learn about pivot tables in general. Pivot tables are often overlooked in Excel as an option.
Lastly, you could get really advanced with Excel Power Queries. Just Google "Excel Power query" and you will be shown all kinds of information on them. They are a close second place in power to manipulate Excel data short of using VBA.
Good luck!
CountA(Unique(D2:D8,,False)) = 5 [Count(Unique(D2:D8)) is the same as False is the default.]
CountA(Unique(D2:D8,,True)) = 3 (once and only once)
Note: the Unique function was released in late 2019 to Office 365. So if you want to use this check your version, not present in 1908, present in 2006.
Edit: It's actually in 2002, I just updated my 1908 machine.
HTH
If names duplicates are removed the following formula can be used: =COUNTIF(B:B,F2)
If duplicates must be removed by formula, MATCH (searches for a specified item in a range of cells, and then returns the relative position of that item in the range.) and SMALL (Returns the k-th smallest value in a data set.) functions can be used as shown.
C$1048576 is used to reference last row number for a big list case.
formulas:
Column A, names sequence
Colunm B, names
Column C, formula =MATCH(B2,B:B,0)
Column D, formula =IF(COUNTIF(C2:$C$1048576,C2)=1,C2,"")
Column E, formula =SMALL(D:D,A2)
Column F, formula =VLOOKUP(E2,A:B,2,0)
Column G, formula =COUNTIF(B:B,F2)
For anyone like me without O265's lovely Unique & Filter Functions, and who doesnt want to use a pivot table, and there are many ways to do this, but this i have just done this in normal excel.
List of data in Column H, Formula in column O3. Drag down. Highlights your distinct and unique values from H.
=IF(COUNTIF(H:H,H28)=1,"U - "&COUNTIF(H:H,H28),IF(COUNTIF(H$1:H27,H28)=1,"U - "&COUNTIF(H:H,H28),"-"))
Formula is short. You can just do this and drag down. Apply the same principal to your worksheet data wherever it is.
=IF(COUNTIF(H:H,H3)=1,"U",IF(COUNTIF(H$1:H2,H3)=1,"U","-"))
Similarly, you can just use this formula here (credit goes to this source for this one):
=(COUNTIF($H$1:$H1,$H1)=1)+0
Id like to point out that the above formula is a better formula than mine. It highlights with a "1" (or with a tweak, the value of your choice) the first time any value is seen/spotted on any given list, whether duplicate or unique.
Whereas mine is a bit "more random" when picking up the "unique and distict" values.
Mine gets there in the end, but Extend Office's gets there first, as I think is proper (getting the first time a unqique distict value is spotted/occurs.).
Formula in K5 =IF((COUNTIF($H$5:$H5,$H5)=1)+0=1,"UNIQUE DIST","") and drag down...
You could append/add a normal basic countif after the results to show how many actual times the given value appears if you wanted. :
=IF((COUNTIF($H$5:$H5,$H5)=1)+0=1,"UNIQUE DIST","")&" - "&COUNTIF(H:H,H5)

Excel Dynamic Array Spill Area - can it go along a row or just down a column?

The point of this exercise is to try to make this analysis quicker/easier to update. I had it pretty dialed in using a data tab and a pivot table, copying and pasting values/formulas as needed to update. I am trying to improve on that by using Excel's new Dynamic Arrays.
My table is setup with four employee detail columns (Location Name, Location Number, Employee Name, Employee Number), and several (many) columns for dates worked. My issue is the dates worked.
I am using UNIQUE and FILTER to get a list of flagged employees - works as I intended/hoped; lookup formulas to find the location name and number data for each employee from the data table - works as I intended/hoped; and I have been copying/pasting the dates from the pivot table column headers into my "counting"/analysis table header.
What I would like to do is use the UNIQUE formula to get the dates worked - BUT, I want the spill area to go along the row so the dates are column headers. Okay, I probably could have made that a shorter ask, but I hope explaining a little of what I'm trying to do helps. I want the dates to automatically update when I paste new payroll/hours worked data into the data table, the same way the employee data updates.
The key is to TRANSPOSE the UNIQUE formula, not the data:
=TRANSPOSE(UNIQUE(A1:A9))
I cannot find anything about having the spill area go along a row instead of down a column. My workaround for this was to create a column of unique dates next to my data table. Since the data is in a table, the unique dates will update automatically when the table is updated. I used the Offset formula to pull the dates into my column headers from the column of Unique dates next to my data table. I will say, while this setup is easier than updating via the pivot table, it is a formula heavy workbook now.
For the data headers I used : "=OFFSET('Data Table Tab'!$U1,Column()-5,0)". The "rows to offset" portion of the formula is "Column()-5". My first date header is in column 5, so as it is copied to the right this will increment the number of rows to offset from the first date.
At this point I will just need to copy the formulas over to the right to update my analysis table.
I would be surprised if someone else out there just starting to work with the new Dynamic Array formulas in Excel doesn't wonder about the same thing. If you stumble across this question and have a better solution, please feel free to share it with me.

Generate or fill cell data based on another dataset excel

I've a data set that shows;
employee name
date
time work started
time work ended
Now I am trying to have a report like sheet where I can select a certain employee name from a list of employees to view his/her time attended for a particular month.
I tried vlookup but went no where since I need to lookup by two columns plus a row.
Is this possible? without macros or vba.
Thanks
Since name and date are unique identifiers it is possible to use the sumifs function.
For ‘time in’ and ‘Rachel’ this will look as follows:
=Sumifs(column ‘time in’ from data set, column ‘name’ from dataset, “Rachel”, column ‘date’ from data set, “10/01/2017”)
Where Rachel and the date also can be a referenced cell.
=AGGREGATE(15,6,ROW(SHEET1!$A$2:$E$22)/((SHEET2!$B$1=SHEET1!$B$2:$B$22)*(SHEET2!$A4=SHEET1!$C$2:$C$22)),1)
The above formula will grab the row number that matches your criteria. to pull the information you want, you can place the row number inside an INDEX formula to get the following:
=INDEX(SHEET1!$D:$E,AGGREGATE(15,6,ROW(SHEET1!$A$2:$E$22)/((SHEET2!$B$1=SHEET1!$B$2:$B$22)*(SHEET2!$A4=SHEET1!$C$2:$C$22)),1),COLUMN(A1))
You can place the above in your first Time cell and copy right and down. You will see errors if criteria do not exist. ie no person of that name or no date data for that person. to avoid this you can wrap the whole thing in an IFERROR like the below:
=IFERROR(INDEX(SHEET1!$D:$E,AGGREGATE(15,6,ROW(SHEET1!$A$2:$E$22)/((SHEET2!$B$1=SHEET1!$B$2:$B$22)*(SHEET2!$A4=SHEET1!$C$2:$C$22)),1),COLUMN(A1)),"Nothing found")
if you would rather a blank than nothing found display change the "nothing found" to "" or 0 if you want 0 to be displayed.
Note: Aggregate is performing array like calculations in this case. As such you do not want to full column references as it will cause a lot of unnecessary calculations to be performed. Because you have unique entries, SUMIFS option given in another answer is a much better choice.
I think a pivot table will do the job for you.
Place the employee name in the filter, place date and
times in the rows.
Remove subtotals from the Pivot Table
Change Table layout to tabular and Repeat rows
Right click on the Time In and select Ungroup
Then you have the image below.
I have the following layout:
In B11 write this formula and drag down:
=INDEX($B$2:$E$5,MATCH($B$7&$A11,$B$2:$B$5&$C$2:$C$5,0),3)
In C11 write this and drag down:
=INDEX($B$2:$E$5,MATCH($B$7&$A11,$B$2:$B$5&$C$2:$C$5,0),4)
Note that these are Array-Formulas, so you need to enter them with CTRL + SHIFT + ENTER instead of the normal Enter.
You will get a #NV error if the employee hasn't worked on one of the dates A11 and A12. So you could surround the Formula with IFERROR to avoid this.

Culminating numerous workbooks with dynamic arrays to one single workbook, excel

I will have a defined number of identical workbooks within excel for each member of staff, at present this is 3. I want to have a master workbook where I can consolidate the data from all 3 workbooks. If there was a defined number of inputs I could obviously just copy and paste the data over or use a macro to make it seem more 'live'. However, it will be unknown how many inputs each member of staff will have and the only way I could imagine doing it is by the following equation (however I would use the workbook reference):
=IF(Sheet1!A1<>"",Sheet1!A1,IF(Sheet2!A1<>"",Sheet2!A1,IF(Sheet3!A1<>"",Sheet3!A1,0)))
However, when you drag the formula down it will give the obvious problem of putting the value of Sheet2!B13 in the 13th cell if there were only 12 inputs in SheetA, I would need to know the final value of the first sheet to reference the second sheet - but they are dynamic.
Any help would be appreciated.
If you want to find the last row of an area by a formula in Excel;
You need Table:
Select your area.
Click on Formats as Table from Home→Styles, and select one of then
Now you have DESIGN tab that you can see the Table Name like Table1.
Now, you have a table and by this formula you can find number of rows of your table:
=ROWS(Table1)
And by this formula you can find number of columns of your table:
=COLUMNS(Table1)
And when you want to know its value try this (The final value):
=INDIRECT(T(ADDRESS(ROWS(Table1)+1; COLUMNS(Table1)))
NOTE : By using Tables you Don't need to specify your sheet.

Resources