View Single Post
  #6   Report Post  
Biff
 
Posts: n/a
Default what is a dumb or smart formula

I'm feeling really dumb right now!

=SUM(--(WEEKDAY(ROW(INDIRECT(1/1/5&":"&1/26/5)))=4))
=INT((1/26/5-WEEKDAY(1/26/5+1-4)-1/1/5+8)/7)



As written, neither of those formulas work. If I replace the date strings
with either cell references or use an addional function, Datevalue (which
would be dumb!), then they do work. The first formula is an array and can be
made a non-array by using Sumproduct.

The second formula is very nice (Daniel M. always comes up with these slick
date formulas!) but............

How (why?) does it work?

The only part of it that I understand is /7!

Please explain the logic..........

WEEKDAY(1/26/5+1-4)

Why do you add 1 then subtract 4? What is the significance of that? What
does that mean?

Same thing for:

1/1/5+8

Why do you add 8 to the start date? What is the significance of that? What
does that mean?

Here's another thing to consider regarding the topic of this thread: How
does one know if their solution is "dumb" or "smart" ?

Is it "dumb" to use formulas you don't understand?

Biff

"Bernd Plumhoff" wrote in message
...
Hi dede,

If I interprete smart=efficient and dumb=not_as_efficient then this might
be your example:

Task: Count the occurences of Thursdays between 1-Jan-2005 and
26-Jan-2005.

"Dumb" function:
=SUM(--(WEEKDAY(ROW(INDIRECT(1/1/5&":"&1/26/5)))=4))

"Smart" function (by Daniel M.):
=INT((1/26/5-WEEKDAY(1/26/5+1-4)-1/1/5+8)/7)

Both functions calculate the correct result 4. But the "dumb" function
needs about 20x more execution time (due to FastExcel) since it first
generates the whole date sequence and counts all occurences then.

HTH,
Bernd