Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Count If Statement

Status
Not open for further replies.

Jeremiah31

Programmer
Nov 7, 2006
31
US
Never created a "If" statement in Crystal.

Trying to count keyrec's are between 0 to 2 work days.

Should the formula be something like


Count(IIf({@WorkDays} Between 0 to 2,{iSeriesSQL_FADC_Unfinalized_Keyrec.KEYREC}))
 
I tried using:

Iif ( Between ( {@WorkDays}, 0, 2 ), Count({iSeriesSQL_FADC_Unfinalized_Keyrec.KEYREC})


I received an error message, ")" is missing?

Two questions, What is the difference between IF and IIF?

What does ")" is missing mean?
 
Your formula needs another ')' at the end.
Iif ( Between ( {@WorkDays}, 0, 2 ), Count({iSeriesSQL_FADC_Unfinalized_Keyrec.KEYREC}))

IIF is called an immediate if. Kind of a very basic form of if.

IF allows a more structered if statement:
If condition
Then Do_True
Else Do_False.
 
Are you trying to count this for the entire report and then show it in the report footer?
If so, then try this:

If {@WorkDays} in 0 to 2 then 1 else 0

Place this formula in the details section and suppress it.
Right-click the formula and from the shortcut menu, choose Insert Summary.
Choose to place the summary in the report footer.

You could also use a Running Total field, but they're slower as they evaluate in the 2nd pass.


Bob Suruncle
 
Bob's approach is more likely to give correct results, since the syntax:

if field=x then count(y) will just give you the total count for the report if the last record meets your criterion. You need to approach this by making the detail row conditional on your criterion and then insert a summary, as Bob shows.

-LB
 
Maybe try Iif ( Between ( {@WorkDays}, 0, 2 )),

I think the problem is that you have two opening brackets for the IIF statement and only one closing.

It is also much quicker to use Running Totals, which do the work for you. It saves programmer time, though the machine certainly has to do more work. In context, which is more important?

As for
What is the difference between IF and IIF?
Iif is intended to work like Visual Basic - which I'm not familiar with, I prefer to let Crystal do most of the work.

It helps to give your Crystal version - 8, 8.5, 9, 10, 11 or whatever. Methods change between versions, and higher versions have extra options.

[yinyang] Madawc Williams (East Anglia, UK). Using Windows XP & Crystal 10 [yinyang]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top