not working, here sum range and criteria range also are horizontal
i tried the same and got the answer but not working with next headers.
here need one formula that works with all headers
Check if its work for you?
Paste this formula in E2 and copy down.
=TEXT(INDEX(A2:C2,,IFERROR(MATCH("Total",A1:C1,0),MATCH("Total",$A$1:$C$1,0))),"#;;;")