I need to heavily modify the layout of my data. My starting point is something like (I have a lot of rows, so I would like to use some formula or macro):
t1 a
t2 b
t3 c
What I'm trying to obtain is:
t1 a
t2 a
t2 b
t3 b
t3 c
Unfortunately I'm no Excel expert, so I tried with some simple IF formulas but with no success. Any idea and suggestion would be greatly appreciated!
I'm using Excel in english version.
Thanks!
UPDATE
In particular, in the first column I have time values in seconds, while in the second column I have ID of a product. For the sake of simplicity let's assume this:
time [s] ID
1 102
3 105
5 110
6 107
and what I need to get is
time [s] ID
1 102
3 102
3 105
5 105
5 110
6 110
6 107
Obviously time is always incrementing, while the IDs are random.
Assuming your data is in the A and B columns and that your first row is the "header" row (i.e. a row with just column headers), you can use the following formulas to get the desired results:
= INDEX(A:A,FLOOR((ROW()+1)/2,1)+1)
= INDEX(B:B,FLOOR((ROW())/2,1)+1)
The first formula, put in cell for example D2 and the second formula, put in cell for example E2 and then drag down as far as necessary.
See below for a working example.
Related
Consider the following sheet/table:
A B
1 90 71
2 40 25
3 60 16
4 110 13
5 87 82
I want to have a general formula in cell C1 that sums the greatest value in column A (which is 110), plus the sum of the other values in column B (which are 71, 25, 16 and 82). I would appreciate if the formula wasn't an array formula (as in requiring Ctrl + Shift + Enter). I don’t have Office 365, I have Excel 2019.
My attempt
Getting the greatest value in column A is easy, we use MAX(A1:A5).
So the formula I want in cell C1 should be something like:
=MAX(A1:A5) + SUM(array_of_values_to_be_summed)
Obtaining the values of the other rows in column B (what I called array_of_values_to_be_summed in the previous formula) is the hard part. I've read about using INDEX, MATCH, their combination, and obtaining arrays by using parenthesis and equal signs, and I've tried that, without success so far.
For example, I noticed that NOT((A1:A5 = MAX(A1:A5))) yields an array/list containing ones (or TRUEs) for the relative position of the rows to be summed, and containing a zero (or FALSE) for the relative position of the row to be omitted. Maybe this is useful, I couldn't find how.
Any ideas? Thanks.
Edit 1 (solution)
I managed to obtain what I wanted. I simply multiplied the array obtained with the NOT formula, by the range B1:B5. The final formula is:
=MAX(A1:A5) + SUM(NOT((A1:A5 = MAX(A1:A5))) * B1:B5)
Edit 2 (duplicate values)
I forgot to explain what the formula should do if there are duplicates in column A. In that case, the first term of my final formula (the term that has the MAX function) would be the one whose corresponding value in column B is smallest, and the value in column B of the other duplicates would be used in the second term (the one containing the SUM function).
For example, consider the following sheet/table:
A B
1 90 71
2 110 25
3 60 16
4 110 13
5 110 82
Based on the above table, the formula should yield 110 + (71 + 25 + 16 + 82) = 304.
Just to give context, the reason I want such a formula is because I’m writing a spreadsheet that automatically calculates the electric current rating of the short-circuit protective device of the feeder of a group of electric motors in a house or building or mall, as required by the article 430.62(A) of the US National Electrical Code. Column A is the current rating of the short-circuit protective device of the branch-circuit of each motors, and column B is the full-load current of each motor.
You can use this formula
=MAX(A1:A5)
+SUM(B1:B5)
-AGGREGATE(15,6,(B1:B5)/(A1:A5=MAX(A1:A5)),1)
Based on #Anupam Chand's hint for max-value-duplicates there could also be min-value-duplicates in column B for corresponding max-value-duplicates in column A. :) This formula would account for that
=SUM(B1:B5)
+(MAX(A1:A5)-AGGREGATE(15,6,(B1:B5)/(A1:A5=MAX(A1:A5)),1))
*SUMPRODUCT((A1:A5=MAX(A1:A5))*(B1:B5=AGGREGATE(15,6,(B1:B5)/(A1:A5=MAX(A1:A5)),1)))
Or with #Anupam Chand's shorter and better readable and overall better style :)
=SUM(B1:B5)
+(MAX(A1:A5)-MINIFS(B1:B5,A1:A5,MAX(A1:A5)))
*COUNTIFS(A1:A5,MAX(A1:A5),B1:B5,MINIFS(B1:B5,A1:A5,MAX(A1:A5)))
The explanation works for bot solutions:
The SUM-part just sums the whole list.
The second line gets the max-value for column A and the corresponding min-value of column B for the max-values in column A and adds or subtracts it respectively.
The third line counts, how many times the corresponding min-value for the max-value occurs and multiplies it with the second line.
Can you try this ?
=MAX(A1:A5)+SUM(B1:B5)-MINIFS(B1:B5,A1:A5,MAX(A1:A5))
What we're doing is adding the max of A to all rows of B and then subtracting the min value of B where A is the max.
If you have Excel 365 you can use the following LET-Formula
=LET(A,A1:A5,
B,B1:B5,
MaxA,MAX(A),
MinBExclude, MINIFS(B,A,MaxA),
sumB1,SUMPRODUCT(B*(A=MaxA)*(B<>MinBExclude)),
sumB2,SUMPRODUCT(B*(A<>MaxA)),
MaxA +sumB1+sumB2
A and B are shortcuts for the two ranges
MaxA returns the max value for A (110)
MinBExclude filters the values of column B by the MaxA-value (25, 13, 82) and returns the min-value of the filtered result (13)
sumB1 returns the sum of the other MaxA values from column B (26 + 82)
sumB2 returns the sum of the values from B where value in A <> MaxA (71 + 60)
and finally the result is returned
If you don't have Excel 365 you can add helper columns for MaxA, MinBExclude, sumB1 and sumB2 and the final result
I have 2 columns:
A B
apple_type1 25
apple_type1 15
apple_type1 5
pears_type1 10
pears_type1 3
apple_type2 5
apple_type2 15
It is posible to Subsum the column B (without deleting the rows, whithout filters, without Pivot table) like:
apple_type1 0
apple_type1 0
apple_type1 45
pears_type1 0
pears_type1 13
apple_type2 0
apple_type2 20
Thank you!
If column A is sorted, then you could also use =IF(A1=A2,0,SUMIF(A:A,A2,B:B)) copied down:
This would be faster than using COUNTIF within the same formula, referring to Error 1004's answer (COUNTIF and SUMIF all need to 'look' at the range, so having two of these in the same formula will consume twice as much resources, but it has the advantage that it doesn't require column A to be sorted).
If you need to refresh the data a lot of times (new information got added for example), then I would advise sorting then using the formula I proposed.
Modify the formula and try:
=IF(COUNTIF(A3:$A$9,A2)>0,0,SUMIF($A$2:$A$8,A2,$B$2:$B$8))
Results:
I'm not sure if I'm over complicating this...
basically I'd like to have a formula which is
if the c column is less than 6, then look up the max value in B but display the value of C
so far I have this but I'd like it to show 2, not 437
{=MAX(IF(C2:C12<6,B2:B12, 0))}
any advice is appreciated. i'm shy, be nice..thanks
A B C
cat 110 3
dog 148 4
rooster 36 7
duck 32 8
pig 437 2
horse 44 6
eagle 215 5
dolphin 21 1
panda 2 9
iguana 257 10
fish 199 11
edit:
maybe something like
{=INDEX(C2:C12,MATCH(MAX(IF(C2:C12<6,C2:C12)),C2:C12,0))}
but I don't see where to put b2:b12
You really need two conditions
1) Column B is equal to =MAX(IF(C2:C12<6,B2:B12))
2) Column C is <6
so you can INDEX column C when those two are met, i.e.
=INDEX(C2:C12,MATCH(1,(B2:B12=MAX(IF(C2:C12<6,B2:B12)))*(C2:C12<6),0))
confirmed with CTRL+SHIFT+ENTER
{=IF(C2<6,INDEX($C$2:$C$12,MATCH(MAX($B$2:$B$12),$B$2:$B$12,0)),0)}
You were almost there..
Basically if C<6 , find max of B , lookup it in B:C and display corresponding C
{=IFERROR(VLOOKUP(MAX(IF(C2:C12<6,B2:B12, 0)),B2:C12,2,FALSE),0)}
Since your question doesn't clarify what if c>=6 I assume you don't want value.
Can answer more precisely if you clarify.
Mark this as answer if that's correct.
Hope this helps!
As I could see you requested a single INDEX formula:
{=INDEX($C$2:$C$12,MATCH(MAX(IF($C$2:$C$12<6,$B$2:$B$12,0),0),IF($C$2:$C$12<6,$B$2:$B$12,0),0))}
This is an array formula, hit Ctrl+Shift+Enter while still in the formula bar.
Lets break this down.
=INDEX(C:C, - Index column C as these are the values you want returned
MATCH(IF(C:C<6,B:B,0), - Find the largest value from the following array in the array and return it's relative position for INDEX()
IF(C:C<6,B:B,0),0)) - If the value in column c is less than 6 then add the column B value to the array, otherwise add 0
I have an excel worksheet with something like below. The desired output are as shown in column G and the last row, which concatenates all the values in columns/rows and gives the value of the resultant expression.
It's actually some kind of a puzzle where the aim is to replace some numbers with operators such that the values in G matches with a specified value. I am replicating the same in excel from a paper version.
A B C D E F G
3 3 33
4 1 + 2 43
4 0 + 5 6 4 604
7 3 2 / 1 2 61
3 7 2 7 3727
3 0 30
47 4033 304 0.4 2617 42
I have tried the following formula:
="="&A2&B2&C2&D2&E2&F2
However it gives the result in text format instead of 43, which I expected:
=41+2
Is there any way to give the final output as 43.
I developed (recorded and modified) a macro which simply copies the above result, paste it as values in Column H and then run 'text to columns' on the column H which gives me the desired output exactly as expected. However, I still can't figure out how to do the same with the row.
Is there any way to achieve the above with a formula only?
I want to avoid using macros as the undo functionality is lost but suggestions are welcome.
You could create a UDF that uses Application.Evaluate to evaluate the text string into a value. Then your formula would just need =Eval(A2&B2&C2&D2&E2&F2)
Function Eval(txt As String)
Eval = Application.Evaluate(txt)
End Function
I have a column of values, and then I have two columns with simple marking like just an 'X':
A B C
1
2
3 VALUES: PERSON1: PERSON2
4 500 X
5 180 X
6 100 X
7 200 X
8 TOTAL:
9 =SUM(A4:A8) ?? ??
Can I create a statement that will check that if a box has an X in it the value of the A-column cell on the same row will be subtracted from the total summation?
In the example above PERSON2 should have a statement with the values '=980-180-100' which is 700.
I can easily do it for one cell: =IF(B4="X", A9-A4) but I can't quite get around with doing with multiple.
I suspect:
=SUM(A4:A7)-SUMIF(B4:B7,"X",A4:A7)
is what you are after, or perhaps:
=SUM(A4:A7)-2*SUMIF(B4:B7,"X",A4:A7)
but a better solution is from #barry houdini:
in B9 try this formula copied to C9 =SUMIF(B4:B7,"<>X",$A4:$A7)
You can use something like
=$A9-SUMIFS($A4:$A7,B4:B7,"X")