Flow control

Intermediate Google Sheets

Richie Cotton

Data Evangelist at DataCamp

If this then that

A B C
1 Value Command Result
2 TRUE =IF(A2, "1st", "2nd") 1st
3 FALSE =IF(A3, "1st", "2nd") 2nd

 

A B C
1 Value Command Result
2 5 =IF(A2 > 0, "positive", "negative") positive

Intermediate Google Sheets

Dealing with lots of conditions

A B C D
1 Value1 Value2 Command Result
2 TRUE FALSE =IFS(A2, "1st", B2, "2nd") 1st
3 FALSE TRUE =IFS(A3, "1st", B3, "2nd") 2nd
4 TRUE TRUE =IFS(A4, "1st", B3, "2nd") 1st
5 FALSE FALSE =IFS(A5, "1st", B5, "2nd") #N/A
Intermediate Google Sheets

Transforming categorical variables

A B C
1 Value Command Result
2 1st =SWITCH(A2, "1st", 1, "2nd", 2) 1
3 2nd =SWITCH(A3, "1st", 1, "2nd", 2) 2
4 3rd =SWITCH(A4, "1st", 1, "2nd", 2) #N/A
Intermediate Google Sheets

Summary

  • IF(condition, yes, no) lets you return a value based on a logical condition.
  • IFS(condition1, value1, condition2, value2) extends this to multiple conditions.
  • SWITCH(condition, category1, value1, category2, value2) lets you transform categorical variables.
Intermediate Google Sheets

Let's practice!

Intermediate Google Sheets

Preparing Video For Download...