 ShowAll Questionssorted byDate Posted Anil Dutt

# Formula Filed to return value

Hi,

I have some fileds for Passenger like

p1_First_Name__c , p1_Last_Name__c

p2_First_Name__c , p2_Last_Name__c

p3_First_Name__c , p3_Last_Name__c

I want to create a Formula Filed which return value on following condition

int i =0;

if(p1_First_Name__c !=null && p1_Last_Name__c !=null)

then  i = i +1;

if(p2_First_Name__c !=null && p2_Last_Name__c !=null)

﻿﻿﻿﻿then i= i +1;

and so on

So of all filed are not null then total of 4 value will return

If 3 fileds  not null then value will be 3

Thanks Best Answer chosen by Admin (Salesforce Developers)  Anil Dutt

SRK

Thanks for all you help

but following did the trick

IF(OR(ISBLANK(p1_First_Name__c) ,ISBLANK(p1_Last_Name__c)),0,1) + IF(OR(ISBLANK(P2_First_Name__c) , ISBLANK(P2_Last_Name__c)),0,1) +
IF(OR(ISBLANK(P3_First_Name__c) , ISBLANK(P3_Last_Name__c)),0,1) + IF(OR(ISBLANK(P4_First_Name__c) , ISBLANK(P4_Last_Name__c)),0,1)  +
IF(OR(ISBLANK(P5_First_Name__c) , ISBLANK(P5_Last_Name__c)),0,1)

and looks very cleaner SRK

If u start int i =0; & all 3 have value the max value is 3 not 4

if 1 & 3 rd is null & 2nd hava data then value is 1 rite ??
correct me if i was wrong Anil Dutt

yes , you are right SRK

hmmmm
i put the logic

int x = 1;

if(p1_First_Name__c !=null && p1_Last_Name__c !=null)

x = x + 1;

if(p2_First_Name__c !=null && p2_Last_Name__c !=null)

x = x+ 1;

if(p3_First_Name__c !=null && p3_Last_Name__c !=null)

x = x+ 1;

if i understand it correct u can try the below mention formula

IF(AND(ISBLANK(p1_First_Name__c),ISBLANK(p1_Last_Name__c)),IF(AND(ISBLANK(p2_First_Name__c),ISBLANK(p2_Last_Name__c)),IF(AND(ISBLANK(p3_First_Name__c),ISBLANK(p3_Last_Name__c)),4,3),IF(AND(ISBLANK(p3_First_Name__c),ISBLANK(p3_Last_Name__c)),3,2)),IF(AND(ISBLANK(p2_First_Name__c),ISBLANK(p2_Last_Name__c)),IF(AND(ISBLANK(p3_First_Name__c),ISBLANK(p3_Last_Name__c)),3,2),IF(AND(ISBLANK(p3_First_Name__c),ISBLANK(p3_Last_Name__c)),2,1)) Anil Dutt

Can't we use some temporary variable to hold incremneted value?

like

int  x = 0;

X = X + 1; SRK

No i dont think so

hmmmm i look for it if i find anything i will let u know Anil Dutt

Thanks, If we use variables it will be much cleaner and understandable Anil Dutt

SRK,

Also you have created it for Null check

but i want to check not null condition

Will you please re-write it with not null check? SRK

try this
IF(NOT(AND(ISBLANK(p1_First_Name__c),ISBLANK(p1_Last_Name__c))),IF(NOT(AND(ISBLANK(p2_First_Name__c),ISBLANK(p2_Last_Name__c))),IF(NOT(AND(ISBLANK(p3_First_Name__c),ISBLANK(p3_Last_Name__c))),4,3),IF(NOT(AND(ISBLANK(p3_First_Name__c),ISBLANK(p3_Last_Name__c)),3,2))),IF(NOT(AND(ISBLANK(p2_First_Name__c),ISBLANK(p2_Last_Name__c))),IF(NOT(AND(ISBLANK(p3_First_Name__c),ISBLANK(p3_Last_Name__c))),3,2),IF(NOT(AND(ISBLANK(p3_First_Name__c),ISBLANK(p3_Last_Name__c))),2,1)) Anil Dutt

SRK

Thanks for all you help

but following did the trick

IF(OR(ISBLANK(p1_First_Name__c) ,ISBLANK(p1_Last_Name__c)),0,1) + IF(OR(ISBLANK(P2_First_Name__c) , ISBLANK(P2_Last_Name__c)),0,1) +
IF(OR(ISBLANK(P3_First_Name__c) , ISBLANK(P3_Last_Name__c)),0,1) + IF(OR(ISBLANK(P4_First_Name__c) , ISBLANK(P4_Last_Name__c)),0,1)  +
IF(OR(ISBLANK(P5_First_Name__c) , ISBLANK(P5_Last_Name__c)),0,1)

and looks very cleaner

This was selected as the best answer SRK

Grate  :) swamy

Hi,Anil you are writing is that for what purpose.....we can't understood that.....Just give me a small description.... Anil Dutt

@swamy

The purpose is to get How many passengers name has been entered