Try replacing the formula in Q16
with the following:
={query(
{INDIRECT(K21),INDIRECT(K20),INDIRECT(K19),INDIRECT(K22),ARRAYFORMULA(XLOOKUP(INDIRECT(K19),V16:V,W16:W,0,0,1))},
"select Col1, Col2, Col3 where Col1 = 'Income' and Col4 <> 'Hide' order by Col2 asc, Col5 desc",0);
query(
{INDIRECT(K21),INDIRECT(K20),INDIRECT(K19),INDIRECT(K22),ARRAYFORMULA(XLOOKUP(INDIRECT(K19),V16:V,W16:W,0,0,1))},
"select Col1, Col2, Col3 where Col1 = 'Expense' and Col4 <> 'Hide' order by Col2 asc, Col5 asc",0)}
(You’ll need to unhide the columns to the right of column I
to find cell Q16
.)