Skip to content

Latest commit

 

History

History
70 lines (42 loc) · 1.75 KB

google_sheet_sheet.md

File metadata and controls

70 lines (42 loc) · 1.75 KB

Google sheet code

Author: Huanfa Chen

Last update: 2023/05/30

The Google sheet used for code demonstration: here

  1. To exclude a value in Cell A3 from a list

    =filter({"aa","bb","cc","dd","ee"},{"aa","bb","cc","dd","ee"}<>A3)
  2. To randomly pick up a value from a list that excludes a value in A3. Note that the random selection depends on all cells in this speadsheet, meaning that if you change any cell in the spreadsheet, the random value will change.

    =INDEX(filter({"aa","bb","cc","dd","ee"},{"aa","bb","cc","dd","ee"}<>A3)), RANDBETWEEN(1,COUNTA({"aa","bb","cc","dd","ee"})-1)))
  3. To do something conditioning on whether a cell A3 is blank

    =if(isblank(A3), sth, sth_else)
    
  4. To count the number of cells in a range (Column A) that equals to a value ("")

    =count(A:A,"")
    
  5. To count the number of cells that meets a criterion (greater than 5)

    =countif(A:A,">5")
    
  6. To count the rows where the Column A value equals Column B (Note that you should use countifs rather than countif)

    =COUNTIFS(A3:A33,B3:B33)
    or
    =COUNTIFS(A:A,B:B)
    
  7. To count the number of cells that meets multiple criteria from multiple columns. Note that countifs doesn't work with isnumber or isna

    =countifs(A:A,">5",B:B,"")
    
  8. To group by a column and get the sum of the values in another column (using SQL syntax)

    =QUERY(A2:C8,"select A, sum(D) group by A")
    
  9. To get the number of occurrences of a value in a column (using SQL syntax)

     =QUERY(W:W,"select W, count(W) group by W")