Forum Discussion

MARK3's avatar
MARK3
Copper Contributor
Oct 30, 2025

Adding to a formula

Hello,

I need to add more to the formula we currently have, but not sure how to add it in. how can i add the value of L & PH so it takes 1 away for the value of L and 0.5 away for PH.

 

(Holiday bkd cell) =IF('SetUp Tab'!$E$6="No",(COUNTIFS($A$13:$A$377,">="&$A$1+1,$A$13:$A$377,"<="&$A$377,Q13:Q377,"H")),(COUNTIFS($A$13:$A$378,">="&$A$1+1,$A$13:$A$378,"<="&$A$378,Q13:Q378,"H")))

(holiday taken cell) =IF('SetUp Tab'!$E$6="No",(COUNTIFS($A$13:$A$377,">="&$A$13,$A$13:$A$377,"<="&$A$1,Q13:Q377,"H")),(COUNTIFS($A$13:$A$378,">="&$A$13,$A$13:$A$378,"<="&$A$1,Q13:Q378,"H")))

 

4 Replies

  • m_tarler's avatar
    m_tarler
    Bronze Contributor

    So I might suggest re-doing the whole formula because it appears to have parts you just don't need

    Let's first break down what you have:

    Holiday bkd and Holiday taken appear to the the exact same except 'taken' is BEFORE the date in A1 and 'bkd' is AFTER the date in A1

    Presumably, you have dates from 1/1 (cell A13) to the end of the year 12/31 (cell A377)

    I'm not sure but I'm guessing that 'SetUp Tab'!$E$6 is if this year is a leap year and you need to include A378

    So instead of an IF statement and repeating the same formula but adding row 378 just include 378 and leave it blank if it is not a leap year.

    Also, since the dates are going up from 1/1 to 12/31 you don't need to check if >= 1/1 or <= 12/31

    so what you need is a reference to the range of value either from 1/1 to the date in A1 or from the day after A1 to 12/31.  This can be achieved using:

    Q13:INDEX(Q13:Q378, A1-DATE(YEAR(A1),1,0))

    so having that range we can then simple do a compare and SUM like this for 'taken':

    =LET(rng, Q13:INDEX(Q13:Q378, A1-DATE(YEAR(A1),1,0)),
              SUM((rng="H")-(rng="L")+0.5*(rng="PH)) )

    and then for 'bkd':

    =LET(rng, INDEX(Q13:Q378, A1-DATE(YEAR(A1),1,0)):Q378,
              SUM((rng="H")-(rng="L")+0.5*(rng="PH)) )

     

  • Riny_van_Eekelen's avatar
    Riny_van_Eekelen
    Platinum Contributor

    You need to add a COUNTIFS( ) for each of code. So, in your first formula the first COUNTIFS [if_true] would become three COUNTIFS like this:

        COUNTIFS(
            $A$13:$A$377, ">=" & $A$1 + 1,
            $A$13:$A$377, "<=" & $A$377,
            Q13:Q377, "H"
        ) -
        COUNTIFS(
            $A$13:$A$377, ">=" & $A$1 + 1,
            $A$13:$A$377, "<=" & $A$377,
            Q13:Q377, "L"
        ) -
        COUNTIFS(
            $A$13:$A$377, ">=" & $A$1 + 1,
            $A$13:$A$377, "<=" & $A$377,
            Q13:Q377, "PH"
        ) * 0.5

    You need to do that also for the [if_false] argument. And similar for the 2nd formula.

     

    • Kidd_Ip's avatar
      Kidd_Ip
      MVP

      How about this:

       

      Holiday Booked Cell

      =IF('SetUp Tab'!$E$6="No",
          COUNTIFS($A$13:$A$377,">="&$A$1+1,$A$13:$A$377,"<="&$A$377,Q13:Q377,"H")
          - COUNTIFS($A$13:$A$377,">="&$A$1+1,$A$13:$A$377,"<="&$A$377,Q13:Q377,"L")
          - 0.5 * COUNTIFS($A$13:$A$377,">="&$A$1+1,$A$13:$A$377,"<="&$A$377,Q13:Q377,"PH"),
          COUNTIFS($A$13:$A$378,">="&$A$1+1,$A$13:$A$378,"<="&$A$378,Q13:Q378,"H")
          - COUNTIFS($A$13:$A$378,">="&$A$1+1,$A$13:$A$378,"<="&$A$378,Q13:Q378,"L")
          - 0.5 * COUNTIFS($A$13:$A$378,">="&$A$1+1,$A$13:$A$378,"<="&$A$378,Q13:Q378,"PH")
      )

       

      Holiday Taken Cell

      =IF('SetUp Tab'!$E$6="No",
          COUNTIFS($A$13:$A$377,">="&$A$13,$A$13:$A$377,"<="&$A$1,Q13:Q377,"H")
          - COUNTIFS($A$13:$A$377,">="&$A$13,$A$13:$A$377,"<="&$A$1,Q13:Q377,"L")
          - 0.5 * COUNTIFS($A$13:$A$377,">="&$A$13,$A$13:$A$377,"<="&$A$1,Q13:Q377,"PH"),
          COUNTIFS($A$13:$A$378,">="&$A$13,$A$13:$A$378,"<="&$A$1,Q13:Q378,"H")
          - COUNTIFS($A$13:$A$378,">="&$A$13,$A$13:$A$378,"<="&$A$1,Q13:Q378,"L")
          - 0.5 * COUNTIFS($A$13:$A$378,">="&$A$13,$A$13:$A$378,"<="&$A$1,Q13:Q378,"PH")
      )

       

Resources