Excel Conditional Formula to evaluate multiple column ranges - excel

Apologies, If the solution is already available, I have been searching for hours!
The problem I am facing is that to put conditional formula based on column ranges for e.g:
Conditions:
1) A1=0, B1=0, C1=0, D1=0 = Result Last Four columns are zero
2) A1=1, B1=0, C1=0, D1=0 = Result Last Three columns are zero
3) A1=1, B1=1, C1=0, D1=0 = Result Last Two columns are zero
4) A1=1, B1=1, C1=1, D1=0 = Result Last column is zero
5) A1=0, B1=0, C1=1, D1=0 = Result Last column is zero
6) A1=0, B1=1, C1=0, D1=0 = Result Last Two columns are zero
7) A1=0, B1=0, C1=0, D1=1 = Result Last Column is Not Empty
The catch in the above results is that the condition should consider the column zeros from right to left.

You can:
Create a named range (I will call it Sentences) to store the hardcoded sentences you want as a result. Below is an example (do not include the header in the named range):
Hardcoded sentences
Four columns are zero
Last Column is Not Empty
Three columns are zero
First two columns are zero
Three columns are zero
Two columns are zero
Two columns are zero
One column is zero
Three columns are zero
Two columns are zero
Two columns are zero
One column is zero
Last Two columns are zero
One column is zero
Last column is zero
No column is zero
Apply this array formula (to be validated using Ctrl+Shift+Enter):=INDEX(Sentences, 1+SUM(2^(COLUMNS(A1:D1)-COLUMN(A1:D1))*(A1:D1<>0)))
Explanation: the formula counts empty cells as bits (weights: 1, 2, 4, 8), adds the bits together to create and index then look into the named range the sentence at the calculated index.
Obviously, you will have to edit the values from the named range if the values I typed do not suit your need.
Edit:
You can also handle only special cases in the range and leave the general case to a more generic formula.
By special cases, I mean things like "Last column is not empty" (only applies to the last column) as opposed to "One column is zero". (applies to all columns).
You can just leave some cells of the named range empty whenever it is a general case and let the formula below do the job.
=IF(
LEN(INDEX(Sentences, 1+SUM(2^(COLUMNS(A1:D1)-COLUMN(A1:D1))*(A1:D1<>0)))) > 0,
INDEX(Sentences, 1+SUM(2^(COLUMNS(A1:D1)-COLUMN(A1:D1))*(A1:D1<>0))),
INDEX({"All columns are zero","Three columns are zero","Two columns are zero","1 column is zero"}, 1+COUNT(IF(A1:D1=0,1)))
)

Related

Count number of cells with a value in each row of a table

I wish to count the number of blank cells within each cell of a column using PQ.
e.g.
There appears to be a count blank function but this counts the number of blank cells vertically. I wish to count the number of blank cells horizontally.
Add index column (using default, that starts at zero)
Then add column ... custom column... with formula
= List.Sum(List.Transform(Record.ToList(Source{[Index]}), each if _=null then 1 else 0))
It converts the row into a record
Then converts the record into a list
Then transforms each item in the list to a 1 if null or 0 if not
Then takes the sum of that
Alternate:
= List.Count(Table.ColumnNames(Source))-List.NonNullCount(Record.ToList(Source{[Index]}))
In all instances, replace Source with the name of your actual prior step

Excel - How can I locate a pattern(s) of matching rows within a large set of numerical data?

I have a large set of data in one column (K), containing random values of 1, 2, 3, and 4. Within that, I would like to locate and highlight sets of rows that match the values from a much smaller column (G) of data.
I tried using Conditional Formatting but was only able to set rules for single rows of data, not matching groups.
Within one Column (K), I expect to locate and highlight all instances of the data I put into another Column (G) (example 1, 2, 1, 1, 2).
In order to do this, you need two helper columns.
A has the pattern you are looking for (=randbetween(1|4)).
B has the random numbers 1 through 4 (=randbetween(1|4)) but is a longer list.
The first helper column D has =IF(AND(B3=$A$2|B2=$A$1)|"match"|"no") which will put "match" on the last row of the pattern.
Then, helper column E has =IF(D3="match"|"match"|"no") to put a "match" in the cell if the one below it has it.
Then, in the conditional formatting for the column is =OR($D1="match"|$E1="match").
This can be expanded to a pattern of 3.
The first helper column K has =IF(AND(I2=$H$2|I1=$H$1|I3=$H$3)|"match"|"no").
The second helper column L has =IF(OR(K3="match"|K4="match")|"match"|"no").
The conditional formatting formula is the same, just transposed over a few rows.
If your pattern is a fixed size, this works great. If your pattern varies in length, you'll have to find a way to generalize these formulas.

Summing the values of one column only up to the depth of another column

If I have rows 1:m populated with values in column A, and in column B I have rows 1:n populated with values, where n < m. How can I find the sum of values in column A from row 1 up to row n.
In other words, how can I sum the values in Column A down to the last row of data in Column B where both Columns may have more values added to new rows at any time.
UPDATE: To ignore text values
=SUMPRODUCT(IFERROR((ROW(A:A)<=MAX(IF(B:B<>"",ROW(B:B))))*A:A,0))
This will produce a 0 value when an error occurs so the formula behaves for values only.
Original Answer:
In addition to the other answer -
If you are looking for total of A where B has a value then:
=SUMIF(B:B,"<>",A:A)
This is pretty self explanitory, =SUMIF(range,criteria,[sum_range]) we check B:B for non blanks and then sum the corresponding cells from A:A.
If you are looking for total of A1:An where n is the last row with a value from column B then:
This will need to be entered as an array formula (when in the formula bar hit Ctrl+Shift+Enter)
=SUMPRODUCT((ROW(A:A)<=MAX(IF(B:B<>"",ROW(B:B))))*A:A)
Array formula's break down ranges and caluclate them them one cell (or row) at a time. The MAX rows is broken down as an array, the IF sormula is returning 0 for false (default) and the row number for true so MAX is then grabbing the highest row number from the array (18 in the below example).
The Sumproduct formula is then producing true/false (1 or 0) for each cell in A:A where the row is less than or equal to the MAX row of non blank entries in B:B.
The formula then multiplies the true/false results (0 or 1) by the value in the corresponding A:A cell thus when the condition is met we have 1 x the value being summed and when the condition is not met then 0 will be summed (0 x the value).
I hope this helps explain the logic, feel free to probe my brain for more of an explanation if not.
The following formula dynamically determines the row of the last entry in column B and sums the values in column A up to this row.
=SUM(A1:INDIRECT("A"&COUNTA(B:B)))

Substract last cell in row from first cell with number

I have the following Excel sheet
In column J i need the final difference between the first cell in the row and the last cell (with a number).
Numbers can appear from column C until column I. Numbers do not always start in column C and do not always end in column I, but there are never empty cells in between.
Basically i need to subtract the value in the first cell with a number from the last cell with a number. The last value in the range from C-I minus the first value in that range with the result being displayed in J.
I filled in column J manually for now, however I would like to do it with formula.
If the numbers are always ordered from smallest to largest, you could simply do this:
=MAX(C2:I2)-MIN(C2:I2)
If not, things become a bit more difficult. Here's another solution that should work for non-ordered entries:
First, add an empty column to the right of Totaal.
Second, add seven columns with the following contents:
=IF(ISBLANK(C2),M2,C2)
=IF(ISBLANK(D2),N2,D2)
...
Third, add another empty column.
Fourth, add seven columns with the following contents:
=IF(ISBLANK(C2),S2,C2)
=IF(ISBLANK(D2),T2,D2)
...
Totaal can then be calculated with
=Z2-L2

How to extract specific/multiple entries from a cell?

Starting from row 1 to row 2468, I have 3 entries of 16 digit numbers in odd rows in a single cell from which I want to extract the first 16 digit number and place it in a single column. In the even numbered cells, I have two 16 digit numbers and I want to extract both of them to two new columns. Thus I want to have three columns with 1st column being the entry from odd row, and next two columns being entries from the even rows. How to proceed?
You need 3 formulas. For the formulas below, the data is in column A, the "Odd" case is going in column B, the first "Even" case is in Column C, and the second "Even" case is in column D.
In column B: =IF(ISEVEN(ROW(A1)),"",LEFT(A1,16))
In column C: =IF(ISEVEN(ROW(A1)),LEFT(A1,16),"")
In column D: =IF(ISEVEN(ROW(A1)),MID(A1,17,16),"") <--this one may need tweaking, depending on how the 16 digit numbers are delimited.

Resources