How to use IF in MS Excel for getting specific column value?

Muhammad Toseef

New Member
Joined
Apr 18, 2017
Messages
1
I have a diseases dataset saved in MS Excel sheet, the format of the data is given below:


I have a diseases dataset saved in MS Excel sheet, the format of the data is given below:

HTML:
| Object Name     | Symptom 1       | Symptom 2       | Symptom 3         |...| Symptom N        | Disease     | 
|      ABC        |     1           |     0           |     0             |...| 1                |    XYZ      |
|      ABC        |     0           |     1           |     0             |...| 0                |    XYZ      |
|      ABC        |     1           |     0           |     1             |...| 1                |    XYZ      |
|      ABC        |     1           |     1           |     0             |...| 0                |    XYZ      |

where the first column is entering variable i.e name of some object and the leaving column i.e. last column is a disease name. The columns in between are the symptoms columns for the specific disease of that object.

Now, for each row in the sheet, I want to get all the symptoms attribute where the value is 1, i.e. this symptom is present, using Disease column as a decision variable. Logic is given below.
Code:
<code>
for each row in the sheet  </code><code>
 -->  IF (Disease = XYZ)
 --> Get all the Symptoms variables where value is 1</code>
<code>

The desired result for the first rows is as follow;

HTML:
Row 1 --> XYZ (Symptom1) 
Row 2 --> XYZ (Symptom2) 
Row 3 --> XYZ (Symptom1, Symptom3) 
Row 4 --> XYZ (Symptom1, Symptom2)

How can I do this in MS Excel, using IF formula? Help in this regard will be highly appreciated.</code>
 

Excel Facts

Square and cube roots
The =SQRT(25) is a square root. For a cube root, use =125^(1/3). For a fourth root, use =625^(1/4).
Welcome to the forum.

If you have Excel 2016 or newer, that has the TEXTJOIN function, you could do something like this:

ABCDEFGHIJKLM
Object NameSymptom 1Symptom 2Symptom 3Symptom 4Symptom 5Symptom NDiseaseDiseasexyz
ABCXYZSymptom 1, Symptom N
ABCXYZSymptom 2
ABCXYZSymptom 1, Symptom 3, Symptom N
ABCXYZSymptom 1, Symptom 2
DEFXXX
DEFXXX
DEFXXX
DEFXXX

<colgroup><col style="width: 25pxpx"><col><col><col><col><col><col><col><col><col><col><col><col><col></colgroup><thead>
</thead><tbody>
[TD="align: center"]1[/TD]

[TD="align: right"][/TD]

[TD="align: right"][/TD]
[TD="align: right"][/TD]

[TD="align: center"]2[/TD]

[TD="align: right"]1[/TD]
[TD="align: right"]0[/TD]
[TD="align: right"]0[/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="align: right"]1[/TD]
[TD="align: right"][/TD]

[TD="align: right"][/TD]
[TD="align: right"][/TD]

[TD="align: right"][/TD]

[TD="align: center"]3[/TD]

[TD="align: right"]0[/TD]
[TD="align: right"]1[/TD]
[TD="align: right"]0[/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="align: right"]0[/TD]
[TD="align: right"][/TD]

[TD="align: right"][/TD]
[TD="align: right"][/TD]

[TD="align: right"][/TD]

[TD="align: center"]4[/TD]

[TD="align: right"]1[/TD]
[TD="align: right"]0[/TD]
[TD="align: right"]1[/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="align: right"]1[/TD]
[TD="align: right"][/TD]

[TD="align: right"][/TD]
[TD="align: right"][/TD]

[TD="align: right"][/TD]

[TD="align: center"]5[/TD]

[TD="align: right"]1[/TD]
[TD="align: right"]1[/TD]
[TD="align: right"]0[/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="align: right"]0[/TD]
[TD="align: right"][/TD]

[TD="align: right"][/TD]
[TD="align: right"][/TD]

[TD="align: right"][/TD]

[TD="align: center"]6[/TD]

[TD="align: right"]1[/TD]
[TD="align: right"]0[/TD]
[TD="align: right"]0[/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="align: right"]1[/TD]
[TD="align: right"][/TD]

[TD="align: right"][/TD]
[TD="align: right"][/TD]

[TD="align: right"][/TD]

[TD="align: center"]7[/TD]

[TD="align: right"]1[/TD]
[TD="align: right"]1[/TD]
[TD="align: right"]1[/TD]
[TD="align: right"]1[/TD]
[TD="align: right"]1[/TD]
[TD="align: right"]1[/TD]
[TD="align: right"][/TD]

[TD="align: right"][/TD]
[TD="align: right"][/TD]

[TD="align: right"][/TD]

[TD="align: center"]8[/TD]

[TD="align: right"]0[/TD]
[TD="align: right"]0[/TD]
[TD="align: right"]0[/TD]
[TD="align: right"]0[/TD]
[TD="align: right"]0[/TD]
[TD="align: right"]0[/TD]
[TD="align: right"][/TD]

[TD="align: right"][/TD]
[TD="align: right"][/TD]

[TD="align: right"][/TD]

[TD="align: center"]9[/TD]

[TD="align: right"]1[/TD]
[TD="align: right"]1[/TD]
[TD="align: right"]0[/TD]
[TD="align: right"]1[/TD]
[TD="align: right"]0[/TD]
[TD="align: right"]1[/TD]
[TD="align: right"][/TD]

[TD="align: right"][/TD]
[TD="align: right"][/TD]

[TD="align: right"][/TD]

[TD="align: center"]10[/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]

[TD="align: right"][/TD]

</tbody>
Sheet8

[TABLE="width: 85%"]
<tbody>[TR]
[TD]Array Formulas[TABLE="width: 100%"]
<thead>[TR="bgcolor: #DAE7F5"]
[TH="width: 10px"]Cell[/TH]
[TH="align: left"]Formula[/TH]
[/TR]
</thead><tbody>[TR]
[TH="width: 10px, bgcolor: #DAE7F5"]L2[/TH]
[TD="align: left"]{=IFERROR(TEXTJOIN(", ",TRUE,IF(INDEX($B$2:$G$9,SMALL(IF(($I$2:$I$9=$M$1)*(SUBTOTAL(9,OFFSET($B$2:$G$2,ROW($B$2:$B$9)-ROW($B$2),0))>0),ROW($I$2:$I$9)-ROW($I$2)+1),ROWS($M$2:$M2)),0)=1,$B$1:$G$1,"")),"")}[/TD]
[/TR]
</tbody>[/TABLE]
Entered with Ctrl+Shift+Enter. If entered correctly, Excel will surround with curly braces {}.
Note: Do not try and enter the {} manually yourself[/TD]
[/TR]
</tbody>[/TABLE]



Put the formula in L2, change the ranges to match your sheet, then confirm with Control+Shift+Enter. Then drag it down the column as far as needed. Note that I included a section to exclude items such as row 8 where there are no 1s in any of the symptom columns.


If you don't have the TEXTJOIN function, you'll need some version of VBA. I can help with that, but first let me know if the output format is what you want.
 
Upvote 0

Forum statistics

Threads
1,223,903
Messages
6,175,287
Members
452,631
Latest member
a_potato

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top