How to return the header by value in a PivotTable - excel

I have a PivotTable like this:
Sum of Gf_Amount | Column Labels
| 2015 | | | | Grand Total
Row Labels | 17-Mar | 18-Mar | 19-Mar | 20-Mar |
3601 | 20 | 20 | | | 40
10386 | 35 | | | | 35
76301 | 5 | | | | 5
80941 | | | | 10 | 10
205738 | | | 5 | | 5
219576 | | 15 | | | 15
Grand Total | 60 | 35 | 5 | 10 | 110
What I want do is find the last non-empty column and return the date according to the value. For example: for ID 3601 the result should be 2015 18-Mar.
Currently I know how to find the last non-empty column by using =LOOKUP(9.99E+307,B6:E6). For ID 3601 it gives me 20 which is correct. However when I use:
=INDEX($B$5:$E$5,MATCH(LOOKUP(9.99E+307,B6:E6),B6:E6,0))
to find the header, it gives me 17-Mar which is the corresponding header for the first 20. Besides, the formula I wrote can't even give me the year.
Can anyone help me out so I can find the date and year? (It doesn't have to be in PivotTable. You can copy and paste it in a normal table.)

I'm guessing that your column labels are date indices formatted as dd-mmm so there is no need to find the 2015 that is displayed hence:
=INDEX($5:$5,MATCH(1E+100,A6:E6))
formatted as say dd-mmm-yyyy and presumably copied down may suit.
It is a peculiarity (perhaps never really intended) of the MATCH function that, without the optional argument, where it can’t find a match in a list it returns the index of the last entry in the list – very useful, as here, at times! So all the “big number” (there are lots of versions of it – for example the one you used 9.99E+307) does is feed MATCH a number so large it is never likely to find it (to force selection of the last entry).
I like 1E+100, a googol, as short and easy to remember, and for its ‘derivation’. 9.99E+307 is theoretically better as closer to the largest number Excel can handle:
9.99999999999999E+307
but
10,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000
for me is big enough – I don’t expect ever to want to work with a number bigger than that and smaller than or equal to 9.99E+307.

Related

Finding value on a column based on another column and a parameter

I have 3 columns like this:
+-----+----+-------+
| 50 | 10 | 20 |
| 175 | 30 | 17.14 |
| 150 | 25 | 16.66 |
| 250 | 40 | 16 |
| 100 | 15 | 15 |
+-----+----+-------+
What I want to achieve is when I type a value in a completely other box, I want to find the highest value in C column with the value closest (or equal to) among the ones lower than the value I entered.
For example if I write 56 I want 20 to come as a result or 16.66 for 160.
I don't know if I can parametrize the input (56 and 160 in the example above) in Excel. Would be visually better if I could light up the line for the correct value.
I'm sure this is doable in Excel to some extent but I don't know how.
You haven't explained the purpose of column B but based on your question the following would work:
Formula in F2:
=INDEX(C1:C5,MATCH(MIN(ABS(A1:A5-E2)),ABS(A1:A5-E2),0))
Note It's an array formula which need to be confirmed through CTRLSHIFTENTER
Without pressing CSE, you could use the following formula:
=INDEX(C1:C5,MATCH(MIN(INDEX(ABS(A1:A5-E2),)),INDEX(ABS(A1:A5-E2),),0))

Return the running total of a specific item # from a non-static list of multiple item #'s

I am trying to create a simplified logistics spreadsheet that has a static tab of items (titled 'Items available') and their available quantities that, for each item, displays the running total of that item in inventory by referencing another tab ('Released & added') of items and their continually added & subtracted quantities.
The 'Released & added' tab will be a dynamic one and will use positive integers when a part quantity is being added and negative integers when they are being reduced. A formula that counts the number of rows in the dynamic tab in order to determine the table set first would be preferable, but for my own purposes, setting lookup range to a static quantity such as 2000 would suffice.
I have tried using various formulas that utilize INDEX and MATCH, however, I cannot seem to find a solution that properly hashes the table array in the released & added tab and it looks to me as if the AGGREGATE function may be required to do so.
Sheet1:
| Part Code | Available quantity |
|-----------|--------------------|
| ABC123 | Should be 35 |
| XYZ321 | Should be 21 |
| EFG456 | Should be 25 |
Sheet2:
| Part Code | Released / Added |
|-----------|------------------|
| ABC123 | 55 |
| XYZ321 | 28 |
| ABC123 | -12 |
| EFG456 | 35 |
| EFG456 | -10 |
| XYZ321 | -7 |
| ABC123 | -8 |
Right, you seem to benefit from using SUMIF()
The formula used in B2 translates to:
=SUMIF(Sheet2!$A$2:$A$8,Sheet1!A2,Sheet2!$B$2:$B$8)

Excel: How to sum a column to date from a specified date where date ranges are involved

I'm sure i have seen this done with a short formula but i am struggling to remember how to do it.
I am trying to find where a date falls in an interval and sum another column, from that point in the interval, to the end of all specified date intervals.
So, in the image below the intervals are in columns D and E and the date to find is in cell F1 i.e. 12/12/2016.
I want to find where 12/12/2016 falls within the ranges and sum column F accordingly i.e. 12/12/2016 - 13/12/2016 (2 days) and then all intervals after will be 2 + 6+2+1+3 = 14. I am returning this result in cell J14.
I have used the idea of histograms to calculate this currently, but the formula is large and unwieldy, and i just know i have seen a similar question, somewhere on SO but can't find it, that does this with SUMPRODUCT and OFFSET only. I guess FREQUENCY could also be used.
So what i have currently is:
=SUMPRODUCT(OFFSET(F6,MATCH(TRUE,OFFSET(E6,0,0,COUNT(E6:E1048576),)>F1,0)-1,0,COUNTA(F6:F1048576),))-(F1-OFFSET(D6,MATCH(TRUE,OFFSET(E6,0,0,COUNT(E6:E1048576),)>F1,0)-1,,,))
Where, if i broke it down into stages, i find which bucket (range) has the target value:
={MATCH(TRUE,OFFSET(E6,0,0,COUNT(E6:E1048576),)>F1,0)}
I calculate the distance into the range with:
=F1-OFFSET(D6,H13-1,,,)
And i sum from this point until the end of the range with:
=SUMPRODUCT(OFFSET(F6,H13-1,0,COUNTA(F6:F1048576),))-I13
So, can anyone help me with a shorter more efficient formula please?
Data:
| Start of measurement | 12/12/2016 | |
|----------------------|------------|----------------|
| | | |
| | | |
| | | |
| From | To | Number of days |
| 13/11/2016 | 17/11/2016 | 5 |
| 10/12/2016 | 13/12/2016 | 4 |
| 03/02/2017 | 08/02/2017 | 6 |
| 06/12/2017 | 07/12/2017 | 2 |
| 09/12/2017 | 09/12/2017 | 1 |
| 12/12/2017 | 14/12/2017 | 3 |
This should work for you:
=SUMIF(E6:E11,">="&F1,F6:F11)-F1+INDEX(D6:D11,MATCH(F1,D6:D11))
How about this?
=SUMIFS(F6:F11,D6:D11,">="&F1)+MINIFS(E6:E11,E6:E11,">="&F1)-F1+1
The SUMIFS() gives the 6+2+1+3 part and the MINIFS() - F1 + 1 gives the 2 part.
Note that the ___IFS() functions are more recent and not available in older versions of Excel.

How to find duplicate adjacent cells in Excel

I have 2 columns in Excel (like below) and I would like to identify (conditionally format) any rows that are exactly the same.
As you can see 326.001 1,000 HOUR are identical for the first 3 rows, I would like to highlight or mark these rows so I can see that they are not unique.
+---------+------------+
| ID | INTERVAL |
+---------+------------+
| 326.001 | 1,000 HOUR |
| 326.001 | 1,000 HOUR |
| 326.001 | 1,000 HOUR |
| 326.001 | 3,000 HOUR |
| 326.002 | 1 MONTH |
| 326.002 | 1 YEAR |
| 326.002 | 5 YEAR |
| 326.002 | 500 HOUR |
| 326.002 | 500 HOUR |
| 326.002 | 500 HOUR |
| 326.002 | 1,000 HOUR |
| 326.002 | 1,000 HOUR |
| 326.002 | 1,000 HOUR |
| 326.002 | 3,000 HOUR |
| 326.009 | 3 MONTH |
| 326.009 | 1 YEAR |
| 326.01 | 3 MONTH |
+---------+------------+
I would add a third column: EqualityTest, with a formula such as:
=AND([#ID]=A5,[#INTERVAL]=B5)
This assumes the data is sorted.
The above formula is for row 5, with ID and Interval in columns A and B. Copy-Paste the formula down, and apply conditional formatting to highlight False for unique values.
qroberts,
I'm not clear on your question.
If you're actually attempting to remove duplicate rows, Excel offers that as a function on the basic ribbon bar for the "Data" ribbon: the button (!) is "Remove Duplicates" in the "Data Tools" section on the "Data" ribbon.
If, instead, you are looking for a highlighter which will identify duplicates, things are a bit more complicated, as you need a macro which will find duplicates and then turn on some form of formatting/highlighting (I suggest formatting a background color).
For a macro which will highlight duplicates, we need to hear a bit more to understand your needs. If you have two different sets of duplicates, do you want them highlighted to different colors? If the number of duplicate sets
gets large, this could be a problem.
As another poster has noted, it also matters whether your candidate set is sorted. A full range search for duplicates would be an interesting bit of coding.
So use COUNTIFS():
=COUNTIFS($A$2:$A$10000,$A2,$B$2:$B$10000,$B2)>0
It will return true for any that has duplicates in both columns. This formula does not care if the data is sorted or not.

Counting the frequency of combinations of numbers (in excel using VBA)

I want excel to count the FREQUENCY that certain number-letter combinations appear down a column in excel (using vba). All my data goes down one column like this:
Column A (only 1,2,3,4,5,s,f appear)
1
2
s
4
3
s
4
2
f
2
s
2
s
I want to count the number of occasions combinations of (1-s, 2-s, 3-s, 4-s, 5-s) occur, strictly when the number occurs first (is in the higher row). I do not want to count occasions when the s comes before the number (e.g. s-2). I know how to count the number of individual letters/numbers using the countIf function.
I might later want to expand my analysis to look at the occasions that three letter-number combinations (e.g. 2-s-3, 2-s-5)
I am very much a VBA noob.
Try inserting a new column to the right of Column A. Use this formula =A1&A2 and fill it down the column. The values will look like this:
+----------+----------+
| Column A | Column B |
+----------+----------+
| 1 | 12 |
| 2 | 2s |
| s | s4 |
| 4 | 43 |
| 3 | 3s |
| s | s4 |
| 4 | 42 |
| 2 | 2f |
| f | f2 |
| 2 | 2s |
| s | s2 |
| 2 | 2s |
| s | s |
+----------+----------+
Now you can count occurences like you were doing before! :D
Of course, you can expand to three character frequency analysis by making the formula =A1&A2&A3.
Seems possible with COUNTIFS, with 1 to 5 inclusive in C1:G1 and in C2:
=COUNTIFS($A1:$A12,C1,$A2:$A13,"s")
copied across to suit.
You can use the VBA equivalent of this formula
=SUMPRODUCT(--(ISNUMBER(A1:A12)),--(A2:A13="s"))
which looks for number, followed by s in the row below (4 for your sample)
code
MsgBox Evaluate("SUMPRODUCT(--(ISNUMBER(A1:A12)),--(A2:A13=""s""))")

Resources