Link to home
Start Free TrialLog in
Avatar of JameMeck
JameMeckFlag for United States of America

asked on

Excel dynamic sum.

My excel file:

DATE                              1                   2                  3                  4                   5                    6
TTL Cast target             1,082        2,173        1,520        2,245        2,286        2,184




My parameter:  a
If a = 3 --> =sum(B2:D2)
if a = 2 --> = sum(B2:C2)

How can I do it?

ASKER CERTIFIED SOLUTION
Avatar of jppinto
jppinto
Flag of Portugal image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Or do you want it to consider other values for a?
Avatar of Statick001
Statick001

=IF(condition, result if true, result if false)

so, here it would be :
=IF(a=3, sum(B2:D2), IF(a=2, sum(B2:C2), 0))

if a is neither 3 or 2 then the result is 0
Where will the parameter come from

If it is in say cell a2 you could use something like

=SUM(INDIRECT(ADDRESS(1,2)):INDIRECT(ADDRESS(1,2+ A2)))

Michael

Avatar of Rory Archibald
=SUMIF(B1:F1,"<"&A3,B2:F2)
for example assuming your value (3 or 2 or whatever) is in A3.
Typo:
=SUMIF(B1:F1,"<="&A3,B2:F2)
...or you could use INDEX, something like

=SUM(B2:INDEX(B2:Z2,A3))

regards, barry