Search code examples
arraysgoogle-sheetsexcel-formulaflattengoogle-query-language

How can I compare duplicate columns, each with a range of numbers, and return error if their ranges of numbers overlap to each other?


I am fairly new to googlesheets and I apologize for the poor explanation beforehand. As the title suggests, what I'm trying to figure out using googlesheet formulas is:

  1. Go through an entire column for duplicates
  2. Within those duplicates, compare their ranges of numbers and check for any overlapping number
  3. If any number overlaps, return error

Google Sheet Link : Click Here

Within the googlesheet above, Row 13 would have a problem since Row 13's Math's Page 8 overlaps with Row 8's Page 8.

So far, what I had in mind and tried was to split ranges of numbers into multiple columns so that I could compare each of those columns to duplicates' ranges of numbers, but I'm not sure what to do after from here. Another assumption is that I would need only to compare only the latest column to check for duplicate Course and overlapping range, but I'm not sure what to use here too.

I appreciate any tips and/or formulas to try out.


Solution

  • try:

    ={"Warning"; INDEX(SUBSTITUTE(REGEXREPLACE(IFNA(VLOOKUP(B3:B&"", TRIM(SPLIT(FLATTEN(
     QUERY(QUERY({SEQUENCE(COLUMNS(SPLIT(TEXTJOIN(",", 1, D3:D), ","))),
     QUERY(FLATTEN(IF(IFERROR(SPLIT(D3:D, ","))="",,B3:B)), 
     "where Col1 is not null")&"×", 
     IF(COUNTIFS(QUERY(FLATTEN(IF(IFERROR(SPLIT(D3:D, ","))="",,C3:C&SPLIT(D3:D, ","))),
     "where Col1 is not null"), 
     QUERY(FLATTEN(IF(IFERROR(SPLIT(D3:D, ","))="",,C3:C&SPLIT(D3:D, ","))),
     "where Col1 is not null"), SEQUENCE(COLUMNS(SPLIT(TEXTJOIN(",", 1, D3:D), ","))), 
     "<="&SEQUENCE(COLUMNS(SPLIT(TEXTJOIN(",", 1, D3:D), ","))))>1, "Error,", 
     QUERY(FLATTEN(IF(IFERROR(SPLIT(D3:D, ","))="",,SPLIT(D3:D, ","))), 
     "where Col1 is not null")&",")}, 
     "select max(Col3) group by Col1 pivot Col2"),,9^9)), "×")), 2, 0)), ",$", ), ", ", ","))}
    

    enter image description here