Formula to put 1 in the first value and 0 for the rest. Duplicate dataset - excel

I'm looking for a smart way to indicate only one row with duplicated values. I need it to help my pivot table a little.
Id Description Estimation(h) Formula
1 Desc1 20 1
1 Desc2 20 0
1 Desc3 20 0
2 Desc4 30 1
2 Desc5 30 0
2 Desc6 30 0

This looks quite simple: I just put the value 1 as the first value, and the rest of the column is based on the following formula:
=IF(A2=A3;0;1)
(I've put this formula in cell D3)

This option will work even if the Id is not sorted:
=--(COUNTIF($A$2:A2,A2)=1)

Related

Finding maximum value in group

I want to create a column of data that finds the largest value in column BD, based on individual values in Column B. I would have thought this equation would work! Anyone have any recommendations??
(first attempt)
=IF(BD3=0,0,SUMIFS($BD$3:$BD3,$B$3:$B3,B3,$BD$3:$BD3,MAX($BD$3:$BD3)))
(Second attempt)
=IF(BD3=MAXIFS($BD$3:$BD3,$B$3:$B3,B3),MAXIFS($BD$3:$BD3,$B$3:$B3,B3),0)
Projectid(B)
cumulative production(BD)
result I want()
1
20
0
1
60
0
1
70
70
2
0
0
2
0
0
3
20
20
4
0
0
5
0
0
6
0
0
7
10
0
7
40
0
7
60
60
this code should work:
=IF(MAXIFS($BD$1:$BD$12,$B$1:$B$12,A1)=BD1,MAXIFS($BD$1:$BD$12,$B$1:$B$12,B1),0)
If you have access to LAMBDA() function then can use below formula at one go.
=LET(a,BYROW(A2:A13,LAMBDA(x,MAXIFS(B2:B13,A2:A13,x))),IF(B2:B13=a,a,0))
Similar to SUMIFS you find MAXIFS
https://support.microsoft.com/en-us/office/maxifs-function-dfd611e6-da2c-488a-919b-9b6376b28883
Then just compare the MAX with the actual row value.
Edit based on your reply:
One way is to start with one operation in the cell first then it is easier to follow.
Your MAXIF should be like this (looking for the max in column B of those rows having the same value in column A as the value of current column A)
=MAXIFS(B$2:B$13;A$2:A$13;A2)
Then compare to B2
So, basically you got it, need just to adjust your second part of the MAXIFS :-)

Indexing questions with array formulas in Excel

I'm new to array formulas in Excel and my brain has been trained in R for too long, so I'm sorry if this question is simple or too specific. I have data that looks like this:
ID Iteration Value Group1 Group2
2 1 100 0 0
2 2 85 1 0
2 3 28 0 0
3 1 94 1 0
5 1 83 0 1
5 2 50 1 1
6 1 94 0 0
6 2 28 1 0
I want to use array formulas to query the data in a few different ways. I want to:
For each ID, find the first iteration that has Group1 = 1.
For each ID, what is the maximum value when Group1 = 1.
For each ID, how many iterations of Group1 = 1 did it take to get to the maximum value when Group1 = 1.
I've figured out how to specify the maximum for each ID via: {=MAX(IF(A:A=A2,C:C))}
Any assistance would be appreciated. I've gone through a few quick tutorials so far, and I'm willing to look through any other good resources you may know of.
Have a look at this and tell me what you think - particularly for question 3
My setup looks like this
All formulas drag down and they are as follows:
Formula in B14 (Question 1)
{=INDEX($B$2:$B$9,MATCH(1,($A$2:$A$9=A14)*($D$2:$D$9=1),0))}
Formula in G14 (Question 2)
{=MAX(($A$2:$A$9=$F14)*($D$2:$D$9=1)*$C$2:$C$9)}
Formula in K14 (Question 3)
{=SUM(($A$2:$A$9=J14)*($C$2:$C$9=G14)*$B$2:$B$9)}
Update
If you want to know how many times in ID=2 that Group1=1 before we reach the maximum we found for ID =2 in question 2, then I'd proceed like this:
Add another column to your data, I labeled it: Group1 Passes. Placing this in the new column, F2, and drag down.
=COUNTIFS($A$2:A2,A2,$D$2:D2,1)
You can then use the following in K14
=SUM(($A$2:$A$9=J14)*($C$2:$C$9=G14)*($D$2:$D$9=1)*$F$2:$F$9)

Find Largest Value in one cell and then display a different cell in the same row

This was a fairly difficult question to put to words but hopefully the example data and my attempt will help
I have the following
Apple 17 1 0 0 0 0 0 0 0 0 0 0
Orange 14 1 15 1 6.67 1 6.67 1 6.67 2 13.33 10
Banana 15 3 5 0 0 0 0 0 0 0 0 1
Cherry 13 1 12 2 16.67 2 16.67 2 16.67 2 16.67 2
Peach 16 4 12 1 8.33 1 8.33 2 16.67 2 16.67 8
Strawberry 12 5 6 1 16.67 1 16.67 1 16.67 1 16.67 7
I am trying to find the max value in M and then display A from the same row. So in this example the max value would be 10 and "Orange" should be displayed.
It should be noted that I am using 2 sheets, "Data" has my output and "Raw Data" has... the raw data
=VLOOKUP(MAX('Raw Data'!M1:M6), A1:M6, 1, FALSE)
This produces #N/A and I think it might have something to do with my data either not being formatted into a table (though doing so seems to fail with a different error) or running from one sheet to the other.
Any input would be greatly appreciated
VLOOKUP requires that the value to find is in the first column.
Use INDEX/MATCH:
=INDEX(A1:A6,MATCH(MAX(M1:M6),M1:M6,0))
Try this =INDIRECT(ADDRESS(MATCH(MAX(M1:M6),M1:M6,0),1))
I recomend using Index Match as Scott Craner has shown.
But if you are set on using vlookup:
I will first shortly explain vlookup as how I have understood it.
First a limitation, vlookup can only return values to the left of your search range, i.e you cant use negative numbers i.e,
=vlookup(Max('Raw Data'!M1:M6), A1:M6, **"-1"**, False)
Secondly, vlookup is structured like this:
=vlookup(The value you want to search for, the range you want to work with, which column you want to return a value from (1 means the first column).
vlookup will allways search for the vale you want to search for in the first column.
So in your data:
You are telling vlookup to search for the maximum value that exists in the range M1:M6. In this case 10 right?
You are telling vlookup to search for this value in column A which contains the fruits. This is where it goes wrong.
My solution to this would be to move all the fruits names to the N column (to the left of you values you want to search).
In code:
In the N Column:
Put = A and the row number
Now do a vlookup like this:
=vlookup(Max('Raw Data'!M1:M6), M1:N6, 2, False)
I hope this can solve your problem.
Best regards,

Combine VLOOKUP and SUMIF in one step

What I want to do (if possible) is sum each metric of each transaction with a common customer_id in ONE STEP. The output should look like the "DESIRED OUTPUT" sheet. I know some sort of lookup will need to be used to reference the "CUSTOMER LOOKUP" table.
I can see how to accomplish this using VLOOKUP then SUMIF (or the other way around), but I would like to accomplish it using a single formula if possible.
TRANSACTIONS
transaction customer_id metric_1 metric_2
1 1 0 564
2 1 0 762
3 1 5.305 8367
4 2 0 150
5 2 3.125 4109
6 2 6.18 1853
7 3 0 61
8 3 0 1
9 3 0 4
CUSTOMER LOOKUP
customer_id customer_name
1 XXX
2 YYY
3 ZZZ
DESIRED OUTPUT
customer_name metric_1 metric_2
XXX 5.305 9693
YYY 9.305 6112
ZZZ 0 66
I doubt it can be done with one formula. This is a very common scenario and is typically solved by adding a Vlookup column to the first table to show the customer name.
Then you can build a pivot table with a few clicks.
I guess, since using a pivot table does not involve formulas, the only formula you need is the Vlookup. So, yes, it can be done with one formula ;-)

Finding the first ocurrence of a string below a given cell?

I've been trying to figure this out but I don't seem to get it right.
I have a spreadsheet with reports for different categories detailed by day (e.g. Toys, Drinks, General Store, Meat Store, Veggies, etc)
So, my spreadsheet looks something like this:
Toys
Day Me Wife Kid1 Kid2
9/28/13 0 0 0 0
10/1/13 29 3 0 0
10/2/13 0 7 34 25
10/4/13 0 0 0 0
AVERAGE 29 5 34 25
.
Drinks
Day Me Wife Kid1 Kid2
9/30/13 102 15 0 0
10/1/13 0 0 25 0
AVERAGE 102 20 0 0
etc etc
So the idea would be that I need to be able to find the Average row number for each different category, but I can't just look for it easily because in one category there might be expenses on more months (hence, more rows between the category's title and the average row). Any clues?
You can use
=ROW()+MATCH("AVERAGE",$A2:$A$1001,0)-1
The row reference to A2 is variable and you can paste it next to the category of interest. The row reference to A1001 is just far enough down in your spreadsheet to include all the data, and is fixed (but doesn't have to be).
You can use something like this perhaps:
=MATCH("AVERAGE",INDIRECT("A"&MATCH("Drinks",A:A,0)&":A1000"),0)+MATCH("Drinks",A:A,0)-1
MATCH("Drinks",A:A,0) returns the row number of Drinks
Which is used by INDIRECT and to convert into a range, from which MATCH then returns the number of rows after that header. Add to the number of rows before Drinks and remove 1 to get the actual row number.
Change the range of A1000 accordingly. I assumed a maximum of 1000 rows here.
Edit, if you have cross-sheet referencing, you need to change the formula to:
=MATCH("AVERAGE",INDIRECT("'Sheetname'!A"&MATCH("Drinks",'Sheetname'!A:A,0)&":A1000"),0)+MATCH("Drinks",'Sheetname'!A:A,0)-1
Assuming Sheetname is the name of that sheet.

Resources