Expanding a table of frequencies in Excel into a single column - excel

I've read elsewhere on Stack Overflow that Excel questions are acceptable here, so please don't get annoyed :) If they should be elsewhere, just let me know...
I'm frustrated, because I'm pretty sure I used to know how to do this.
Imagine the following table:
Frequency Object
3 A
2 B
4 C
In a third column, I want Excel to write:
A
A
A
B
B
C
C
C
C
(3 A's because frequency of A = 3)
I'm pretty sure that this can be done by a single formula copied down the third column, but I can't remember how. Any suggestions?

I liked the elegance of (1) formula, but it will only work if you dont have repeated objects (data).
This will always work, as long you dont have a numeric, diferent from zero, value in E2
Freq values in E3:E6 and Obj in D3:D6, formula starting in P3
=LOOKUP(ROWS(P$3:P3)-1;SUMIF(INDIRECT("E2:E"&ROW($E$2:$E$6));">0");$D$3:$D$6)
or (and, in this case, you can have anything in E2)
=INDEX($D$3:$D$6;IF(ROWS(L$3:L3)<=$E$3;1;1+MATCH(ROWS(L$3:L3)-1;SUMIF(INDIRECT("E3:E"&ROW($E$3:$E$6));">0"))))
Ctrl+Shift+Enter in P3 and copy down
CR

In the first cell of your desired output column (E1 in this example), enter
=B1
Where B1 is the address of the first object. In the cell below (E2, here), enter
=IF(COUNTIF(E$1:E1,E1)=INDEX($A$1:$A$3,MATCH(E1,$B$1:$B$3,0)),
INDEX($B$1:$B$3,MATCH(E1,$B$1:$B$3,0)+1),
E1)
And fill down as far as you require.

Assuming you have a small finite number of objects like in your example, try this:
In a blank sheet, put your example table in the top left. So Cell A2=3, B2="A", A3=2, etc.
In D2, enter "A" (this is just to get the formula started)
In D3, enter this formula:
IF(COUNTIF($D$2:D6,$B$2)<$A$2,$B$2,
IF(COUNTIF($D$2:D6,$B$3)<$A$3,$B$3,
IF(COUNTIF($D$2:D6,$B$4)<$A$4,$B$4)))
Fill this formula down (i.e. copy&paste) about 10 rows and you'll see everything fill in accordingly.
What does it do, you ask? First, it counts the number of occurrences of "A" in the previous cells of column D and compares it to the frequency. If less, it enters another A. Then that process is repeated for B and C.

Related

In Excel, how to fill blank cells in a column, with last preceding non-blank cell in row?

I need a formula that will find the last non-blank cell in each row and use that value to fill blank cells in the same row at last column. Any cells with values in the last column will remain intact. I have not tried any formula yet. The figure below may explain better:
Normally a formula cannot refer to the cell in which the formula is. It leads to the Circular Reference error.
I am not sure if you can reach the desired result using iterative calculation (which kind of allow circular references), but the general purpose of iterative calculation is for numerical methods, not for searching for the last cell in a row :)
How are your cell values filled?
If you fill them programmaticaly, you know what is in your data and you may calculate the last column in the programmatical process.
If you fill them manually, you can live with the extra last column, which you then copy over to last column (Paste Values Only).
Or, as you properly named it in your comment, you may use the "last observation carried forward" approach:
Fill all the cells with formula "copy the value from the left".
Put your data where you do have them (i.e. overwrite the formula with actual data), leave your formula in the "empty" cells where you don't have the data.
As a result, in the last column you will have either your formula carrying the last known value, or the number you entered there.
It's difficult to give you a better advice without knowing the whole process - I still suspect a kind of the X-Y problem, you have not persuaded me enough :) It is clear that you want the last measured value, but is a self-referencing formula in the last column really the only way to achieve your goal? Cannot you look at your problem out of the box and solve it otherwise?
You can create another sheet and use something like the following to fill the blanks.
Sheet1 (Data)
A
B
C
D
E
F
G
H
I
12
14
Sheet2 (Output)
A
B
C
D
E
F
G
H
I
=Sheet1!A1
=IF(Sheet1!B1,Sheet1!B1,A1)
=IF(Sheet1!C1,Sheet1!C1,B1)
=IF(Sheet1!D1,Sheet1!D1,C1)
-> Drag till end
which will result in something like this
A
B
C
D
E
F
G
H
I
12
12
12
14
14
14
14
14
14
You could use this formula in the empty cells of column L.
=LOOKUP(2,1/(A2:K2<>""),A2:K2)
To enter it in the blank cells select column L, go to Find & Select> Go To Special...>Blanks, enter the column in the formula bar and commit it with CTRL+ENTER.

How can i count the frequency of those of a number showing from a countif but only once?

Hi I have a bunch of data and I need to know how much of each value show up and how often the frequency is only corresponding to the unique value. I used a countif to count the unique value but I wanna know the frequency of the amount of times it shows up.
Sorry if this doesnt make any sense here's a screenshot to maybe help you understand better.
https://imgur.com/a/hLUY5um
Change the formula in B1 to,
=IF(COUNTIF(A$1:A1, A1)=1, COUNTIF(A:A, A1), TEXT(,))
and fill down to match the values in column A.
Copy column B into column E then Sort and Remove Duplicates¹.
This simplifies the formula in F1 to,
=COUNTIF(B:B, E1)
Fill down to match the values in column E.
¹ The Custom Number Format for column E is F\r\eq 0_).

Reference every second cell in Excel formula

I currently have a formula like this:
=ROUND((('Sheet1'!D77-'Sheet1'!D75)/'Sheet1'!D75)*100,1)
with the next cell below that:
=ROUND((('Sheet1'!D79-'Sheet1'!D77)/'Sheet1'!D77)*100,1)
What I want is to drag the formula down and to reference every 2nd cell. So for e.g. it should go from referencing D79-D77 to D81-D79 (and not D80-D78) etc. How can I go about doing this?
Thanks
You can also do it with INDEX, multiplying the row that the formula is in relative to the first row by 2 and adding it to either 75 or 77:
=ROUND(((INDEX(Sheet1!D:D,77+(ROWS(A$1:A1)-1)*2)-INDEX(Sheet1!D:D,75+(ROWS(A$1:A1)-1)*2))/INDEX(Sheet1!D:D,75+(ROWS(A$1:A1)-1)*2))*100,1)
Oh, this is interesting.
Assuming you have your first cell at
B1
and the value you are looking into is in column C, starting at cell
C1
To do this, you need to have number at column A. Start with number 1, counting up. (you may include this in dragging)
So side by side, you have number column at A, while the absolute percentage at column B, and values at C (in alternating row).
I did the arithmetic progression, combined with the address and indirect functions to do the task.
where:
an = a1 + (n-1) * d
in B1, the code should look like this:
=(INDIRECT("C"&(3+(A1-1)*2))-INDIRECT("C"&(1+(A1-1)*2)))/INDIRECT("C"&(1+(A1-1)*2))
I guess this should do it.
Cheers..

The max of all possible sequential sums

Is there a way to write this using formulas.
=Max(a, a+b, a+b+c, a+b+c+d, a+b+c+d+e+...)
I don't want to use VBA for this task and I am not sure how to approach this problem.
Excel sheet expanded with formula
Excel sheet contracted without formula
Objectives:
1) For each of the peoples, (Bill, Ben, Katy), I would like to compare the maximum of the sum of only X through time.
For example, in Column J, I would like to know the current Max of the sum of X. Current is the date 1/17/19 because it is the most recent entry.
2) For each of the peoples, (Bill,Ben, Katy), I would like to compare the max of the previous entry to the max of my most recent entry.
For example, in Column K, I would like to compare the Max of the sum of X at 1/5/16 to the max of the sum of X at 1/17/16.
3) I would like Column J and K to recalculate as I bring in new data entries into Column I. As of now, using a solution mentioned below, in Column J, I think I would be using something like this formula:
=MAX(MMULT(0+(ROW(B9:I9)>=TRANSPOSE(ROW(B9:I9))),B9:I9)
This solution seems to work if I only have X's going down vertically though.
Also, as new data gets brought in, Column J and K would be pushed to the right, becoming Column K and L.
4) The highlighted region in Column I and J are my output sections that are dependent on the date of Cell B1.
For example, if I were to change the date to 1/1/2016 in Cell B1, Cell I7 would equal -4 Cell J7 would equal True.
If I were to change the date to 1/17/16 in Cell B1, Cell I7 would equal 5 and Cell J7 would equal True.
I've been playing around with this a bit, trying to use SUMIFS to pick up sum of X based on a date criteria.
I thank everyone in advance for all your help, and I apologize if my wording to this problem is unclear. I am a undergraduate student, and have no background in computer/programming/anything of that sort at all. Thank you so much!
Assuming a, b, c etc are in a column, then a standard approach will be to use an additional column with a cumulative sum of the values in the input column. Then you can just take the MAX of the column with the cumulative sum.
E.g. use of cumulative sum in column B with the input values in column A:
With MAX formula in column C:
Assuming data in A1:A5, you can use this array formula**:
=MAX(MMULT(0+(ROW(A1:A5)>=TRANSPOSE(ROW(A1:A5))),A1:A5))
which, due to its being non-volatile, is preferable to:
=MAX(SUBTOTAL(9,OFFSET(A1:A5,,,ROW(A1:A5)-MIN(ROW(A1:A5))+1)))
Regards
**Array formulas are not entered in the same way as 'standard' formulas. Instead of pressing just ENTER, you first hold down CTRL and SHIFT, and only then press ENTER. If you've done it correctly, you'll notice Excel puts curly brackets {} around the formula (though do not attempt to manually insert these yourself).

How to increment duplicate values from 1 to n by criteria?

let's say I have a list of duplicate values in a column such as:AAABBAACABC. ...AAC. Then I want Excel to Rank respectively the first A as A1,the first B as B1 the second A as A2 and the second B as B2 and so forth until the A(nth) and the B(nth). And any additional A should automatically Rank as A(nth+1). Same thing for B C etc.
note that I should be able to enter any new value such as X that will automatically Rank as X(nth+1) or X1 if it did not exist in the table before.
Hoping that I made myself understood. I am waiting for anyone to help me. VBA or array formulas I have no preference once I can realise what I want.
Note that I found a way by sorting them in accending order but it can't match for any additional value at the end of the data base.
Thanks.
I am assuming your data is in Column "A". Enter the formula in Column "B" and copy the formula till the row you want.
=A1 & IF(A1="","",COUNTIF($A$1:A1,A1))

Resources