google-sheets

Dynamically referencing worksheets to dynamically fill a table based on a condition


Here is a dummy worksheet with the file structure: https://docs.google.com/spreadsheets/d/1RJZW3_lKJkvumcOuSoGLQnZG8NcaTfkJfVm4obTcSq4/edit?usp=sharing

I have a dropdown of language names in Sheet1, an empty table, and a column containing the names of all the sheets in the current document.

I want to dynamically fill the table in Sheet1 with data from the other sheets based on the language selected on the dropdown.

For example, if the user selects "English" from the dropdown, the table on Sheet1 will be dynamically filled with all the School Names where we have students who speak the selected language, and in each row, we'll have the School Name, the student's Age, Name and the Language spoken (which matches the one from the dropdown).

I can't provide an example of what I have already tried because everything I tried failed miserably, I apologize.

Any help is appreciated. Thanks in advance!


Solution

  • Here's one approach you may test out:

    =let(Σ,tocol(,1), reduce(Σ,tocol(F2:F,1),lambda(a,c,vstack(if(iserr(+a),Σ,a),let(Λ,filter(choosecols(indirect(c&"!A4:C"),3,2,1),if(B1="",indirect(c&"!A4:A")<>"",indirect(c&"!B4:B")=B1)),
     Δ,indirect(C&"!A1"), if(isna(Λ),Σ,hstack(wrapcols(Δ,rows(Λ),Δ),Λ)))))))
    

    enter image description here