Let's say there are 4 columns in Sheet 1 with col1 as categories and col2, col3, and col4 are value columns as shown below. In sheet 2, we want to obtain top 2 categories highest sum of values in the selected variable column.
Sheet 1
Sheet 2
I have used the following code to find top values for the table not for each categories, any suggestions to revise this?
=TAKE(SORT(HSTACK(INDEX(Sheet1!B2:D11,,MATCH(H1,Sheet1!B1:D1,0)),CHOOSECOLS(Sheet1!A2:D11,1)),1,-1),5)
Desired output if VAR1 is in user input:
Note: The formulas should not be sensitive to column names in sheet1.



Update as per present edited post by OP:
Try the following formula:
Or,
Or,
• Formula used in cell D2
You can also use the MMULT() in place of SUMIFS(), MMULT() is more resource heavy than SUMIFS, so the latter will be simpler and more efficient, still shared the approach with MMULT()
• Formula used in cell D2
Or,
• Formula used in cell D2
Or,
• Formula used in cell D2
Edited :
As mentioned by OP in comments below:
• Formula used in cell D2
Update:
OP mentions in comments:
Excel can be downloaded from here
As per comments of OP: