Lamloumi Afif
Lamloumi Afif

Reputation: 9081

Getting the average of not null fields

I'm using Crystal reports in my application

average({ConsultationDetail.viandenord} ) 

I need to get the avearge of not null field viandenord

  1. How can i change the formula to get this result?
  2. What is the best way to do that?

Upvotes: 0

Views: 305

Answers (1)

Siva
Siva

Reputation: 9101

Try below code.

If(ISNULL({ConsultationDetail.viandenord}))
Then //Your code
Else average({ConsultationDetail.viandenord} ) 

Edit:....................................................................................... Assuming you have placed your fields in detail section:

  1. Create formula @sum and place below code in the detail and take sum of the field.

    If(ISNULL({ConsultationDetail.viandenord}))
    Then //Your code
    Else {ConsultationDetail.viandenord} 
    
  2. To calculate count create formula @count and write below code and place it after the @sum in detail section.

      if {ConsultationDetail.viandenord}=0
     then 0
    else 1
    
  3. Now take sum of the formula @count

  4. To calculate Average

     Sum({ConsultationDetail.viandenord})/Sum(@count)
    

Above code is just an example.. Let me know how it goes

Upvotes: 2

Related Questions