I want this formula to be dynamic. let it reads the column name for table LastQ from a cell for columns: LOB from b12. Tier from b13. sub b14. configuration from b15. color b16. =LET(
  jarir,         $D$2,
  extra,         $D$3,
  branded,       $D$4,
  unbranded,     $D$5,
  primaryLOB,    $C$12,
  primaryTier,   $C$13,
  primarySSub,   $C$14,
  primaryConfig, $C$15,
  primaryColor,  $C$16,
  sumCriteria, LAMBDA(hq,prog,
    IF(AND( NOT($D$6), NOT($D$7) ),

      SUMIFS(
        lastQ[W1],
        lastQ[[Measure]:[Measure]], $AB$9,
        lastQ[[LOB]:[LOB]], primaryLOB,
        lastQ[[Tier]:[Tier]], primaryTier,
        lastQ[[HQ]:[HQ]], hq,
        lastQ[[Sub]:[Sub]], primarySSub,
        lastQ[[Configuration]:[Configuration]], primaryConfig,
        lastQ[[Color]:[Color]], primaryColor,
        lastQ[[Programm]:[Programm]], prog
      ),
      IF(AND($D$6, $D$7),
        SUM(
          SUMIFS(
            lastQ[W1],
            lastQ[[Measure]:[Measure]], $AB$9,
            lastQ[[LOB]:[LOB]], primaryLOB,
            lastQ[[Tier]:[Tier]], primaryTier,
            lastQ[[HQ]:[HQ]], hq,
            lastQ[[Sub]:[Sub]], primarySSub,
            lastQ[[Configuration]:[Configuration]], primaryConfig,
            lastQ[[Color]:[Color]], primaryColor,
            lastQ[[Programm]:[Programm]], prog,
            lastQ[[STM+]:[STM+]], $C$6
          ),
          SUMIFS(
            lastQ[W1],
            lastQ[[Measure]:[Measure]], $AB$9,
            lastQ[[LOB]:[LOB]], primaryLOB,
            lastQ[[Tier]:[Tier]], primaryTier,
            lastQ[[HQ]:[HQ]], hq,
            lastQ[[Sub]:[Sub]], primarySSub,
            lastQ[[Configuration]:[Configuration]], primaryConfig,
            lastQ[[Color]:[Color]], primaryColor,
            lastQ[[Programm]:[Programm]], prog,
            lastQ[[STM+]:[STM+]], $C$7
          )
        ),
        IF($D$6,

          SUMIFS(
            lastQ[W1],
            lastQ[[Measure]:[Measure]], $AB$9,
            lastQ[[LOB]:[LOB]], primaryLOB,
            lastQ[[Tier]:[Tier]], primaryTier,
            lastQ[[HQ]:[HQ]], hq,
            lastQ[[Sub]:[Sub]], primarySSub,
            lastQ[[Configuration]:[Configuration]], primaryConfig,
            lastQ[[Color]:[Color]], primaryColor,
            lastQ[[Programm]:[Programm]], prog,
            lastQ[[STM+]:[STM+]], $C$6
          ),
          IF($D$7,

            SUMIFS(
              lastQ[W1],
              lastQ[[Measure]:[Measure]], $AB$9,
              lastQ[[LOB]:[LOB]], primaryLOB,
              lastQ[[Tier]:[Tier]], primaryTier,
              lastQ[[HQ]:[HQ]], hq,
              lastQ[[Sub]:[Sub]], primarySSub,
              lastQ[[Configuration]:[Configuration]], primaryConfig,
              lastQ[[Color]:[Color]], primaryColor,
              lastQ[[Programm]:[Programm]], prog,
              lastQ[[STM+]:[STM+]], $C$7
            ),
            0
          )
        )
      )
    )
  ),
  result,
    IF(AND(jarir, extra),
      SUM(
        IF(AND(branded, unbranded),
          sumCriteria("Jarir", "Branded") + sumCriteria("Jarir", "Unbranded"),
          sumCriteria("Jarir", IF(branded, "Branded", IF(unbranded, "Unbranded", "")))
        ),
        IF(AND(branded, unbranded),
          sumCriteria("extra", "Branded") + sumCriteria("extra", "Unbranded"),
          sumCriteria("extra", IF(branded, "Branded", IF(unbranded, "Unbranded", "")))
        )
      ),
      IF(jarir,
        IF(AND(branded, unbranded),
          sumCriteria("Jarir", "Branded") + sumCriteria("Jarir", "Unbranded"),
          sumCriteria("Jarir", IF(branded, "Branded", IF(unbranded, "Unbranded", "")))
        ),
        IF(extra,
          IF(AND(branded, unbranded),
            sumCriteria("extra", "Branded") + sumCriteria("extra", "Unbranded"),
            sumCriteria("extra", IF(branded, "Branded", IF(unbranded, "Unbranded", "")))
          ),
          ""
        )
      )
    ),
  result
)