Count Expression in Visual Studio

I have this Output with Expression (HIT AND MISS)

-------------------------------

Qty1           |      Qty2        |         HIT/MISS

10                         10                        HIT

15                         14                       MISS

20                         20                        HIT

23                         23                        HIT

----------------------------

HIT/MISS - has the Expression:

=Iif(Qty1.Value = Qty2.Value, "HIT", "MISS")

*now I need to COUNT the number of HIT and the Number of Items

output should be:

-------------------------------

Qty1           |      Qty2        |         HIT/MISS

10                         10                        HIT

15                         14                       MISS

20                         20                        HIT

23                         23                        HIT

                                                     HIT: 3 / 4

----------------------------

3 hits in 4 items.

the hard part of this is that the Values are Group, meaning the 4 Values of Qty1 and Qty2 are just SUM of the Group Item.

 


please help me achieve this output. thanks.

September 10th, 2015 8:05am

when i used the code:

=CStr(Sum(IIF(Qty1.Value = Qty2.Value, 1,Nothing))) &  "/" & CStr(Count(Qty2.Value))

the output shown counts all the Qty of the Qty1/Qty2 (i think because the items are grouped)

output:

HIT: 60 / 75

it should be:

HIT: 3/4

Free Windows Admin Tool Kit Click here and download it now
September 10th, 2015 8:06am

Hi XSpy, 

According to your description, you want to calculate the field value, right? 

In our local environment, we have tested this scenario and the report works properly. For your requirement, please refer to the following expression: 

="HIT: " & Sum(IIf(Fields!HITMISS.Value = "HIT", 1,0)) & "/" & Count(Fields!HITMISS.Value)

The result is like below: 

If you have any other question, please feel free to ask. 

Regards,
Shrek Li

September 11th, 2015 3:25am

hello, thanks for the reply.

as i saw your answer/suggestion, there seems to be a misunderstanding(or you didn't read my post well)

ill explain it again here,

The Qty1 and Qty2 is grouped, meaning The first value (10) have many data ex. (3, 3, 4) because it is GROUPED. same as all the other values.

so for the HIT/MISS field, i made it as an Expression:

=Iif(Qty1.Value = Qty2.Value, "HIT", "MISS")

so when I made the HIT/MISS TOTAL, it becomes 60/75 because the one it counts is all the total, not the Grouped one.

i only need the Count, which is HIT: 3/4.

please help me, thanks.


Free Windows Admin Tool Kit Click here and download it now
September 14th, 2015 2:07am

Hi XSpy,

In your scenario, can you get the HIT/MISS field values? If the HIT/MISS field expression can return the correct result, we can use custom code variables to store the result. Please refer to the following steps:

  1.  Add the following code to report code:
Public shared h as Integer
Public shared m as Integer
Public shared Function getValue(Value as String) as String

If Value =  "HIT" then 

h=h+1

else if Value = "MISS" then

m=m+1

end if 

return value

End Function

Public shared Function getHit()
return h

End Function

Public shared Function getMiss()
return m+h

End Function

In the HIT/MISS field text box, use this expression: =Code.getValue(Iif(Qty1.Value = Qty2.Value, "HIT", "MISS"))

Insert a row below the HIT/MISS field, and use this expression: ="HIT: " & Code.getHit() & "/" & Code.getMiss()

The result is like below:

Regards,
Shrek Li


September 14th, 2015 3:29am

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics