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
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 the following Excel spreadsheet:
A B C D E F G
1 Q1 Q2 Q3 Q4 Positive values
2 Asset 1 -50 85 -90 70 85
3 Asset 2 -28 -80 -45 60 70
4 Asset 3 -30 50 55 -10 60
5 Asset 4 -20 5 -80 -15 :
6 Asset 5 35 -30 27 -98 :
7
In Cells A1:E6 I have different assets with their performance from quarter Q1-Q4.
In Column F I create a list of all postive performances of the assets using the formula from here:
Column F = {LARGE(IF($B$2:$E$6>0,B$2:$E$6),ROW(B1:E1))}
All this works fine so far.
However, now I want to exclude certain values from the list in Column F. For example I do not want that number 85 or number 70 appear in the list. Therefore, I tried to modify the formula to:
Column F = {LARGE(IF(AND($B$2:$E$6>0,$B$2:$E$6<>85,$B$2:$E$6<>70),B$2:$E$6),ROW(B1:E1))}
However, now I get 0 as result.
Do you have any idea of a formula that could solve this issue?
Create an array of 0's where 0 is equivalent to a negative number or the excluded values
($B$2:$E$6>0)*($B$2:$E$6<>85)*($B$2:$E$6<>70)
1/(… will convert that to 1's and errors
Multiply by the original to create an array of original values and errors
=1/(($B$2:$E$6>0)*($B$2:$E$6<>85)*($B$2:$E$6<>70)) * B2:E6
Use the aggregate function to get the results you want
=AGGREGATE(14,6,1/(($B$2:$E$6>0)*($B$2:$E$6<>85)*($B$2:$E$6<>70))*$B$2:$E$6,ROWS($1:1))
Fill down to get the 2nd, 3rd, etc largest
You are on the right path. Instead of using AND, a nested IF would work.
You need to create a new IF criteria for every new condition you want to test.
So if you want to exclude 85 and 70 you need to add two additional IF statements.
Formula for Column F would be:
={LARGE(IF($B$2:$E$6>0,IF($B$2:$E$6<>85,IF($B$2:$E$6<>70,B$2:$E$6))),ROW(B1:E1))}
You can read here how the formula process is: Minimum if multiple criteria
If you have data in column F and you want to extract all values that are not 70 or 85 into column G, then in G2 enter:
=IFERROR(INDEX(F$2:F$9999, AGGREGATE(15, 6, ROW($1:$999)/((F$2:F$9999<>85)*(F$2:F$9999<>70)), ROW(1:1))),"")
and copy downwards:
Note that this approach does not require the use of an array formula.
Please forgive any errors or shortcomings in this question, it's my first on stackoverflow.
I have two sets of data in Excel of differing lengths and frequency, and would like to be able to place a value of 0 for where they don't synchronise, and match the rest.
For example, dataset 1 could be:
Date Set1
01-01-2010 10
01-03-2010 4
01-04-2010 8
01-05-2010 5
01-06-2010 10
01-09-2010 12
01-10-2010 9
01-11-2010 4
And dataset 2 could be:
Date Set2
01-03-2010 102
01-06-2010 104
01-10-2010 102
I'm looking for an output table that displays the values alongside each other for dates matching, 0 otherwise, like so:
Date Set1 Set2
01-01-2010 10 0
01-03-2010 4 102
01-04-2010 8 0
01-05-2010 5 0
01-06-2010 10 104
01-09-2010 12 0
01-10-2010 9 102
01-11-2010 4 0
I can't seem to be able to crack this with my limited knowledge and the lack of synchronisation in the data. Any help would be much appreciated, thanks.
You can do this using a VLOOKUP nested in an IFERROR statement.
The two equations used (and dragged down to last unique date row) are:
H3 = IFERROR(VLOOKUP(G3,A:B,2,0),0)) & I3 = IFERROR(VLOOKUP(G3,D:E,2,0),0))
This will not work if you have duplicate dates in the same data set with varying values since VLOOKUP will always return the first matched value (reading top down).
Place Set1 in A1:B9 (header in row 1). Add a column of zeros next to it in column C, so A2:A9 is dates, B2:B9 is values and C2:C9 is zeros.
Place Set2 (without the header) in A10:B12; move the Set2 data to column C and put zeros in column B, so A10:A12 is dates, B10:B12 is zeros, C10:C12 is values.
Sort the range A2:C12 by Date (column A).
Easier to show with a screenshot but newbies are not allowed to post images.
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
w=[1/mn(m^2+n^2)^2)]{sin(m*pi/2)sin(n*pi/2)}
where m and n varies from 1 to 11.
for m=1, n=1,3,5,7,9,11.
for m=2, n=1,3,5,7,9,11.
for m=3, n=1,3,5,7,9,11.
and so on.
Instead of 36 sets of combinations, I need one formula to calculate the set of these 36 combinations and get respective values of w.
Please help me with this equation. I need to solve it in excel.
P.S I'm beginner.
You may create column and rows with heading values of n and m respectively, and calculate the value of w at their intersection. For auto-completion of formula by dragging, you will have to use $ symbol for referencing. See the representation below:
m\n 1 3 5 7 9 11
1 w(1,1) w(1,3) w(1,5) w(1,7) w(1,9) w(1,11)
2 w(2,9) w(3,9) ... so on
3 ...
4
5
6
.
.
Instead of numbers above in w(m,n) use references of column while dragging with a $ sign so that the header row does not change.
EDIT: You need to type the formula only once in at the intersection of (1,1)