I would like to know how to compare for every row that their (numeric) columns have different values or all of them are equal, and get the result (either a boolean or a 0/1) in another column. Something like:
colA colB colC Result
row1 12 12 45 false
row2 67 67 67 true
How could I write this formula concisely in Microsoft Excel? Note that the number of columns may vary and at least I have about 30 columns, so I don't want to name the columns in the formula, but write something like a for
Thank you.
If you want to test only numbers, what about?
=MIN(B1:B30)=MAX(B1:B30)
(if your range goes from 1 to 30)
for doesn't exist in Excel formula, the best way to deal with a for loop would be to use array formulas but this is not appropriated here.
what you may look for is a dynamic range but i can't see a way to implement it easily in your case
[EDIT] new formula thanks to Excelll's comment
=AND(MIN(B1:B30)=MAX(B1:B30),COUNTBLANK(B1:B30)=0)
If blank cells within a row are not an issue, #JMax offers a clever solution. However, if you want a blank cell to return "FALSE", you can use the following array formula:
=AND(EXACT(A1,B1:C1))
Enter this as an array formula by pressing Ctrl+Shift+Enter.
Related
I've been struggling with this for hours now, and I just can't figure out how to add a second criteria to my formula.
I have this table:
device # date plan used
5 12/2/2017 A
8 12/3/2017 A
9 12/4/2017 B
56 12/2/2017 B
588 12/5/2017 C
56 12/2/2017 C
I am trying to get the number of unique devices, that are on plan A and have the date 12/2/2017. Here is the formula I have now.
=SUM(IF(FREQUENCY(IF(D2:D116005=G2,B2:B116005),IF(D2:D116005=G2,B2:B116005))>0,1))
I have successfully counted the unique devices with the criteria of being on 12/2/2017, but I just cannot figure out how to add additional criteria (i.e. on plan A). The G2 cell is where I am storing the date 12/2/2017 for comparison.
I have tried using IF(AND(.. but I can't seem to get it to work.
Could someone help me with this? Let me know if more information is needed.
Thank you,
Staci
You can use multiplication to return a 1 (equivalent to TRUE) if both match:
IF((Table1[date]=TargetDate)*(Table1[plan_used]=TargetPlan),Table1[device_'#],"")
Putting it all together:
=SUM(IF(FREQUENCY(IF((Table1[date]=TargetDate)*(Table1[plan_used]=TargetPlan),Table1[device_'#],""),IF((Table1[date]=TargetDate)*(Table1[plan_used]=TargetPlan),Table1[device_'#],""))>0,1))
Remember this is an array formula so must be confirmed by holding down ctrl + shift while hitting enter
I used structured references and named cells, but you should be able to transfer to your cell references.
in column D, starting in cell D2, put this formula:
=if(and(B2=date(2017,12,2),c2="A",countif($A$2:A2,A2)=1),1,0)
then just sum that column to get your answer.
Assuming plans in column F try this revised array formula:
=SUM(IF(FREQUENCY(IF(D2:D116005=G2,IF(F2:F116005="A",B2:B116005)),B2:B116005),1))
confirmed with CTRL+SHIFT+ENTER
Notice that it's not necessary to repeat the IF functions I the "bins array" argument of the FREQUENCY function
No formulas required: Simply whip up a PivotTable of the data, put Device and Date in the Rows field, and drag Plan to the Values area, which will automatically be given the COUNT treatment by the PivotTable because it's a text field.
The question is slightly confusing, so I will do my best to elaborate. I have a series of cells in a row with all of the cells in the row with a value of 0 and one cell having a value of 1. I want to use the COUNT function to count all of the cells to the right of the cell that contains the value of 1, including that cell. I would then use this number of counted cells in another equation. Does anyone have any suggestions on how to do this? I have tried using a lookup function inside of the count function, but it has not worked. This is my closest guess:
=COUNT(Lookup(1,A1:J1):J1)
This results in an error. Do I need to use VBA to make this work or should I be able to write an equation? I appreciate the help, or if there are any other strategies that I can use to attain the result I am looking for.
Edit: I am adding in some sample data and expected results. I am trying to count all of the cells to the right of the "1" including the cell containing the "1". So in this example, I would expect the formula to return "13" as there are 12 cells to the right of the "1"
You can use OFFSET() and MATCH():
That last "50" is a bit of a guess since I'm not sure how far to the right you want to count...
...and re-reading your question it's not clear if you only want to count values of 1 or if you also need to count other values as long as they're to the right of the first 1.
With data in A1 through J1, consider:
=10-MATCH(1,A1:J1,0)+1
In this case. 4 is the number of cells from G1 through J1, inclusive.
Assuming your range of 0 and 1 values is in row 2, starting from column B, use this formula in B3 and copy it across for as far as you need:
=IFERROR(COUNT($B2:B2)+1-MATCH(1,$B2:B2,0),0)
You could also use a formula of
=IF(A3>0,1+A3,IF(B2=1,1,0))
but that could cause issues if you have something in cell A3 itself.
You can use this formula:
=COUNTA(INDEX($A$1:$J$1,1,MATCH(1,$A$1:$J$1,0)):INDEX($A$1:$J$1,1,10))
The benefit to use this is it is not a volatile function, and it will also work for 1 appears in the last column.
You can use "COUNTIF" formula to count number of occurrences of specific number in a range of cells.
To count no of occurrences in a row.
=COUNTIF(1:1,1)
If it is in a column then
=COUNTIF(A:A,1)
Hope you are looking for a countif function.
COUNTIF(A1:A10, 1)
The above function counts the cell that has value 1 within the range A1:A10
I'm trying to use this formula:
=SUMPRODUCT(VLOOKUP(B$4778,$D$4:$DC$4623,{4,5},0))
It works fine but I'd like to try to use a variable for the {4,5} portion of the formula (columns in the array to be summed) as the formula needs to change based on sheet inputs before this formula.
I have cells on the sheet that are to be used to set the initial and final columns to be searched (likely 10 columns, but the 10 columns would have to be selected from 90 some columns available).The columns are populations related to each age. So, if I need population of those aged 10 through 15, I'd need to sum up 5 columns. If 20-25, need to sum up 5 different columns.
I tried to use the Columns function but it didn't seem to work for me.
The columns are selected by users entering in cells the upper and lower limits of the search range and then I convert those values to the corresponding numerical column value.
So if they select 5 as lower and 10 as upper limit, I know I have to add 7 to get the correct data column on the data page (column 12) and likewise for upper (column 17).
The entire possible area to search is $D$4:$DC$4623. So, in the formula, if I wrote it out long way it would be:
=SUMPRODUCT(VLOOKUP(B$4778,$D$4:$DC$4623,{12,13,14,15,16,17},0))
I'd prefer to write it out using variables, something like this:
=SUMPRODUCT(VLOOKUP(B$4778,$D$4:$DC$4623,{L:U},0))
Where variable L would be 12 and variable U would be 17.
Can anyone suggest a way to write the formula?
use this array formula:
=SUM(VLOOKUP(B$4778,$D$4:$DC$4623,ROW(INDIRECT(D5 & ":" & E5)),FALSE))
Where D5 is the Lower and E5 would be the upper.
Being an array formula it must be confirmed with Ctrl-Shift-Enter instead of Enter when exiting edit mode. If done correctly then excel will put {} around the formula.
Or better yet use this non array formula:
=SUM(INDEX($D$4:$DC$4623,MATCH(B$4778,$D$4:$D$4623,0),D5):INDEX($D$4:$DC$4623,MATCH(B$4778,$D$4:$D$4623,0),E5))
I need to return a median of only a certain category on a spread sheet. Example Below
Airline 5
Auto 20
Auto 3
Bike 12
Airline 12
Airline 39
ect.
How can I write a formula to only return a median value of the Airline Categories. Similar to Average if, only for median. I cannot re-arrange the values. Thank you!
Assuming your categories are in cells A1:A6 and the corresponding values are in B1:B6, you might try typing the formula =MEDIAN(IF($A$1:$A$6="Airline",$B$1:$B$6,"")) in another cell and then pressing CTRL+SHIFT+ENTER.
Using CTRL+SHIFT+ENTER tells Excel to treat the formula as an "array formula". In this example, that means that the IF statement returns an array of 6 values (one of each of the cells in the range $A$1:$A$6) instead of a single value. The MEDIAN function then returns the median of these values. See http://www.cpearson.com/excel/arrayformulas.aspx for a similar example using AVERAGE instead of MEDIAN.
Make a third column that has values like:
=IF(A1="Airline",B1)
=IF(A2="Airline",B2)
etc
Then just perform a median on the new column.
Expanding on Brian Camire's Answer:
Using =MEDIAN(IF($A$1:$A$6="Airline",$B$1:$B$6,"")) with CTRL+SHIFT+ENTER will include blank cells in the calculation. Blank cells will be evaluated as 0 which results in a lower median value. The same is true if using the average funtion. If you don't want to include blank cells in the calculation, use a nested if statement like so:
=MEDIAN(IF($A$1:$A$6="Airline",IF($B$1:$B$6<>"",$B$1:$B$6)))
Don't forget to press CTRL+SHIFT+ENTER to treat the formula as an "array formula".
one solution could be to find a way of pulling the numbers from the string and placing them in a column of just numbers the using the =MEDIAN() function giving the new number column as the range
I recently came to know about Ctrl+Shift+Enter array formulas of Excel and currently still learning them. Coming to my problem,
SheetA:
Product Code
S1 19875
S2 19834
S1 13575
S1 35675
S2 47875
SheetB:
Code Indent
19875 40
19834 15
13575 22
35675 25
47875 20
I need to do Sum of all Indents of a given Product name.
Eg: I need S1's Total Indent,
Vlookup on SheetA, Get the Code 19875
Perform a vlookup on SheetB, Get the Indent of 40
Next Vlookup on Sheet A, Get the code 13575
Use 13575 to Vlookup on SheetB, Get Indent of 22
Next Vlookup on Sheet A, Get the code 35675
Use 35675 to Vlookup on SheetB, get indent of 25
Sum of 40+22+25, Return 87
I can achieve this through VBA, but I'm wondering if this is possible within excel functions using CSE/Array formulas.
Edit:
I don't have values in Sheet2 in the same order of Sheet1.. They are completely random. My SheetB will be something randomly like following:
SheetB:
Code Indent
19834 40
19875 15
47875 22
13575 25
35675 20
{=SUM(NOT(ISNA(MATCH((($A$2:$A$6="S1")*(B2:B6)),Sheet2!$A$2:$A$6,FALSE)))*(Sheet2!$B$2:$B$6))}
The first argument of the MATCH resolves to
{19875;0;13575;35675;0}
The MATCH resolves to
{1;#N/A;3;4;#N/A}
You'll have to make sure you don't have zeros in SheetB. The NOT ISNA turns those into TRUEs and FALSEs and resolves to
{TRUE;FALSE;TRUE;TRUE;FALSE}
And the final SUM looks like this
=SUM({TRUE;FALSE;TRUE;TRUE;FALSE}*{40;15;22;25;20})
Update
I can't figure out a single-array solution when the lists are in a different order. My attempts with OFFSET and TRANSPOSE either gave the wrong answer or crashed Excel. If you can stand using a helper column, you could put this formula in third column of your first sheet
=VLOOKUP(B2,Sheet2!$A$2:$B$6,2,FALSE)
and then use this array formula to sum them up
{=SUM(($A$2:$A$6=A2)*($C$2:$C$6))}
If the Code column were identical (same order) on both SheetA and SheetB, a simple SUMIF function would do. Similarly, if the INDENT data were on SheetA, you could also use a pivot table to calculate the sums quickly.
I'm guessing the design of your workbook won't allow this though. In which case, I don't have any easy solutions, but I'll give it another look.
You could use the below:
//Ola.S
Table 1
Col:A B C
Product Code Intendent
Col C: =SUMIF($E$4:$E$8;B4;$F$4:$F$8)
Table 2
Col:E F
Code Intendent
Table 3
Pivottable (Col:A and C)
On sheetC
If A1 has S1 then in Cell B1 type
=SUM((IF((Product=A1),Code1)=TRANSPOSE(Code2))*TRANSPOSE(Amt))
Array entered
Where
Code1 = Dynamic Range for Codes on SheetA starting from Row2
Code2 = Dynamic Range for Codes on SheetB starting from Row2
No TRANSPOSE calls needed.
Try the array formula
=SUM(SUMIF(SheetB!A2:A6,IF(SheetA!A2:A6="S1",SheetA!B2:B6),SheetB!B2:B6))
Assuming no cell in SheetB!A2:A6 it evaluates to FALSE. If the Code columns were all numeric (probably a questionable assumption), this could be done without an array entry using:
=SUMPRODUCT(SUMIF(SheetB!A2:A6,SheetA!B2:B6/(SheetA!A2:A6="S1"),SheetB!B2:B6))
Assuming no cell in SheetB!A2:A6 evaluates to #DIV/0!.