# writing a function in RDLC on the base of predicate • ### Question

• User-1669453032 posted

Hi , i want to write a function on the base of some logic and taking sum of values on the bases of that predicate.

below can be the predicate. Kindly help me how to create and use that function in RDLC .

`=IIf(StrComp(Fields!PurchaseOrSale.Value,"S",CompareMethod.Text) = 0,"Revenue",IIf(StrComp(Fields!PurchaseOrSale.Value,"P",CompareMethod.Text) = 0,"Expence","Gross Profit"))`

Monday, May 4, 2015 2:06 AM

• User1711366110 posted

Kindly help me how to create and use that function in RDLC .

As per my understanding of this case, you can try with switch statement like below :

Formula1:

```=Switch(
StrComp(Fields!PurchaseOrSale.Value,"S",CompareMethod.Text) = 0, "Revenue",
StrComp(Fields!PurchaseOrSale.Value,"P",CompareMethod.Text) = 0, "Expense",
1=1,"Gross Profit" )```
`=count(Fields!Formula1.Value)`

If you want to sum of values, you can try like below :
Formula1:

```=Switch(
StrComp(Fields!PurchaseOrSale.Value,"S",CompareMethod.Text) = 0, 1,
StrComp(Fields!PurchaseOrSale.Value,"P",CompareMethod.Text) = 0, 2,
1=1, 3 )```
`=sum(Fields!Formula1.Value)`

--
with regards,
Edwin

• Marked as answer by Thursday, October 7, 2021 12:00 AM
Monday, May 4, 2015 9:56 PM

### All replies

• User1711366110 posted

Kindly help me how to create and use that function in RDLC .

As per my understanding of this case, you can try with switch statement like below :

Formula1:

```=Switch(
StrComp(Fields!PurchaseOrSale.Value,"S",CompareMethod.Text) = 0, "Revenue",
StrComp(Fields!PurchaseOrSale.Value,"P",CompareMethod.Text) = 0, "Expense",
1=1,"Gross Profit" )```
`=count(Fields!Formula1.Value)`

If you want to sum of values, you can try like below :
Formula1:

```=Switch(
StrComp(Fields!PurchaseOrSale.Value,"S",CompareMethod.Text) = 0, 1,
StrComp(Fields!PurchaseOrSale.Value,"P",CompareMethod.Text) = 0, 2,
1=1, 3 )```
`=sum(Fields!Formula1.Value)`

--
with regards,
Edwin

• Marked as answer by Thursday, October 7, 2021 12:00 AM
Monday, May 4, 2015 9:56 PM
• User-1669453032 posted

thank you edwin

Saturday, May 16, 2015 7:30 AM