Excel formula for calculating unique occurrences in a column grouped by another column - excel

I need to build a single Excel formula for calculating the third column in the table below based on the previous two columns.
First column shows the name of the active user
Second column shows which week number the activity occurred
The third column should in every row show the total number of unique
weeks that the user in the first colum has been active ever.
------------------------------------------------
NAME ACTIVE-IN-WEEK-NO NUM-UNIQUE-ACTIVE-WEEKS (Need a formula for this one)
------------------------------------------------
JOHN | 50 | 2
ADAM | 48 | 3
PETER | 48 | 1
JOHN | 50 | 2
JOHN | 50 | 2
ADAM | 45 | 3
ADAM | 40 | 3
PETER | 48 | 1
JOHN | 45 | 2
-------------------------------------------------

For this requirement you need to use Microsoft Query ,
refer the link given below :
http://www.excel-easy.com/examples/microsoft-query.html
To Fix this you need to write sql statement in microsoft query.
Hope this Helps.

Assuming your table is in A1:B10 (with headers in row 1), this array formula in C2:
=SUM(IF(FREQUENCY(IF($A$2:$A$10=A2,$B$2:$B$10),$B$2:$B$10)>0,1))
Copy down as required.
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).

Related

Excel Formula or Macro to get the consolidated list from two tables

Question:
Table 1 is as follows.
Name | Hours
john | 12
mark | 20
john | 10
mark | 10
Table 2 is as follows.
Name | Hours
john | 40
mark | 30
These 2 tables are in two diffent workbooks. The Data I need is as follows.
Step 1: From Table 1 I need to consolidate the Column 'Name' and should get the SUm of Column 'Hours'. (i.e) it should be populated as follows.
Table 3
Name | Hours
john | 22
mark | 30
Step 2: Once the above step is achieved I should compare the Column 'Hours' in Table 2 & Table 3 and should populated the result as true or false..
Try this formula:
=IF(SUMIF([Workbook1]Sheet1!$A$1:$B$4;A1,[Workbook1]Sheet1!$B$1:$B$4)=B1,"true","false")
It assumes that Table1 is in Workbook1, Sheet1 in range A1:B4.
I also assumed that Table2 locates in A1:B2 range. Now it's enough to place above formula in C1 cell next to Table2 and drag it down.
Create two pivot tables for both tables and compare accordingly. Then,
=GETPIVOTDATA("Hours",$A$2,"Name",A3)=GETPIVOTDATA("Hours",$A$8,"Name",A9)

How can I conditionally VLOOKUP in Excel?

Suppose I have the table I need to VLOOKUP() through:
id | indicator | value
-----------------------
1 | a | abc
1 | b | def
1 | c | ghi
2 | a | bbc
2 | b | bef
3 | a | aef
There is a table where I need to attach only values with indicator equal to a:
id | value
----------
1 | abc
2 | bbc
3 | aef
Something like conditional VLOOKUP() is required. What is the elegant way to do it?
You can do multiple criteria INDEX-MATCH to achieve this:
=INDEX($C$1:$C$6,MATCH($E1&"a",$A$1:$A$6&$B$1:$B$6,0))
This is array formula and it works by hitting Ctrl+Shift+Enter.
Also, I assumed that your Lookup value is in cell E1, which is something you can change according to your needs.
Use an array formula:
I found this formula in the web a few years ago, cant remember where, but credit to them.
=VLOOKUP(CONCATENATE(D2,"a"), CHOOSE({1,2},A$1:A$10 & B$1:B$10, C$1:C$10 ),2,0)
For this example I used column D on the same sheet for the reference ID and column E for the result. Amend the references as required.
Due to this being an array formula, every time the formula is entered you will need to select the formula bar and hold CTRL and Shift and press enter on the keyboard.

How to use arrayformula to indicate an occurrence in google sheets

I'm trying to write an =arrayformula that finds the 1st, 2nd, 3rd, etc. occurrence of a value in another column. I can do this with a formula copied down all rows but I don't want to use this method, I need the arrayformula to simply always update the column because I need to constantly insert and delete rows and I don't want to have to keep copying the formula down. Thanks in advance.
Google sheet where I'm testing this.
Example formulas that I currently have to copy down..I want this to simply be an arrayformula instead:
values | occurance
aa | =if(A3<>"",countif($A$3:$A3,A3),"") | RESULT:1
2 | =if(A4<>"",countif($A$3:$A4,A4),"") | RESULT:1
aa | =if(A5<>"",countif($A$3:$A5,A5),"") | RESULT:2
5 | =if(A6<>"",countif($A$3:$A6,A6),"") | RESULT:1
5 | =if(A7<>"",countif($A$3:$A7,A7),"") | RESULT:2
4 | =if(A8<>"",countif($A$3:$A8,A8),"") | RESULT:1
Formulas that work but have to be copied down
Check out cell D3 where I used this formula:
=ArrayFormula(iferror(SORT(ROW(A3:A),SORT(ROW(A3:A),A3:A,1),1)-MATCH(A3:A,SORT(A3:A),0)-ROW()+2))
and see if that works for you ?

Increment count in column based on value in column

I've 2 columns A and B. A contains names and B contains the count of those names till that record as shown below.
-----------------------------------
| A | B |
-----------------------------------
1 | Fruits | 1 |
2 | Flowers | 1 |
3 | Fruits | 2 |
So, want to have a formula for this. Expecting an array formula. Even if an array formula is not possible, a general formula
Attached a spreadsheet so that it can be explained better.
https://docs.google.com/spreadsheets/d/1wlWqdFwgv90s50iP-bXXBHciyualohj610qFiSatcmQ/edit#gid=1997586177
You do not need an array formula, and I would avoid them when possible. You can accomplish your task with
=COUNTIF(A$1:A1,A1)
Where A1 if the first value in the column of values you want to count. The $ allows you to anchor the top of your COUNTIF range while leaving the bottom dynamic.
In a google spreadsheet you may want to try:
=ArrayFormula(iferror(SORT(ROW(A1:A),SORT(ROW(A1:A),A1:A,1),1)-MATCH(A1:A,SORT(A1:A),0)-ROW()+2))
Example sheet

Incrementing each row in excel that contains a number

I was sent an excel document in the following format:
A | B |
1 | abc |
| def |
2 | abc |
| def |
| ghi |
3 | abc |
| def |
So basically I have the first column which contains ordered numbers every couple of rows. I want to insert a row e.g. between 2 and 3, so that the new row will be numbered 3, and the rows below it are updated accordingly i.e. 3 becomes 4, 4 becomes 5 and so on.
I don't really use excel, but I am curious if there is there an easy way of doing this?
In A1, enter the following formula:
=IF(MOD(ROW(A1),2)=1,(ROW(A1)+1)/2,"")
And copy that formula down to the bottom of the range. Each time you insert a new row, you will need to manually copy the formula to the inserted row's first cell.
Is there a pattern in the b column, to distinguish if you need to jump to the next number?
if so use:
in cel A2 and further:
=IF(B2 = "abc",A1+1,A1)
With conditional formating, hide the repeating numbers: =A2=A1

Resources