Search code examples
google-sheetsgoogle-sheets-formula

How to convert weekdays to binary-string type? google sheet


The NETWORKDAYS.INTL functions accepts 4 arguments. In which the 3rd argument are the weekdays and in which it is binary-string type e.g. 1000000 (for monday only).

My problem is my sheet accepts array-string in a single cell. Which like for example Monday, Tuesday.

My question is do we have available predefined function that converts Monday, Tuesday to binary-string type e.g. 1100000? If there are none, do you know how to do it? I'm thinking of regex but I don't know how to do it as well in the sheet.


Solution

  • I do not think there is such predefined function.

    You can try:

    =ArrayFormula(JOIN("",N(COUNTIF(MATCH(SPLIT("Monday, Tuesday",", ",0),{"Monday","Tuesday","Wednesday","Thursday","Friday","Saturday","Sunday"},0),SEQUENCE(7))>0)))

    1. Split the input into an array of weekdays
    2. MATCH and get the 1-based index of the weekdays
    3. Convert the presence of the index into binary string