Two things to note:
- SUMIF and SUMIFS expect ranges (not calculated arrays) in some of their arguments
see https://real-statistics.com/excel-capabilities/array-arguments-in-excel-formulas/
- Be aware that SUMIF and SUMIFS require their arguments in a different order.