10 Replies Latest reply on Apr 8, 2016 10:32 AM by ankit.ravi

# Cant Compare Boolean and String Values

I am trying to create a calculated field where I am working with a calculated field (Calculation 1) and comparing them in the calculated field but I am getting an error. I don't seem to find a way around.

I would really appreciate an input on how to solve this issue. I have attached the calculated field.

Thanks
Ankit

• ###### 1. Re: Cant Compare Boolean and String Values

Hi Ankit

There are a number of issues with your formula.

For a start, the error - You can't use numerical operators such as greater than on strings, that doesn't work, they are for numbers

I suspect you wanted to do something like this...

IF [calculation 1] = "Control Segments" OR [calculation 1] = "Test Segments" THEN 1 ELSE 2 END

Example...

Cheers

Mark

• ###### 2. Re: Cant Compare Boolean and String Values

Hey Mark,

Thanks for the reply, I am not sure if this solves my problem. What I am looking to do here is compare the "Control Segment" and "Test Segment" in Calculation 1.

I want to show that when "Revenue" in "Control Segment" is greater than that in "Test Segment" then 1 else 2.

I hope this helps you in assisting me.

Thanks

Ankit

• ###### 3. Re: Cant Compare Boolean and String Values

Hi Mark,

Just a quick errata: strings can be compared:

• ###### 4. Re: Cant Compare Boolean and String Values

Hi Ankit

If i understand you correctly, it maybe first easier to break it down...

First we want the "Revenue" values for "Control Segment", and then we need the "revenue" values for "test segment", once we have these 2 values, we can compare them.

Calc1

IF [calculation 1] = 'control segment' THEN SUM([revenue]) ELSE NULL END

Calc2

IF [calculation 1] = 'test segment' THEN SUM([revenue]) ELSE NULL END

Calc3

IF [Calc1] > [Calc2] THEN 1

ELSE 2

END

Is that clear?

Cheers

Mark

• ###### 5. Re: Cant Compare Boolean and String Values

I tried this out but it gave me 0 in this case 2, so I am not sure whats going wrong with the calculations.

Thanks

Ankit

• ###### 6. Re: Cant Compare Boolean and String Values

Are the string (test segment etc.) matching exactly?

Do you have any in the data?

And if so, do you have any in the data with revenue?

• ###### 7. Re: Cant Compare Boolean and String Values

I dont have any in the data and yes the name matches correctly.

Thanks

Ankit

• ###### 8. Re: Cant Compare Boolean and String Values

and yes the name matches correctly.

that's good

I dont have any in the data

A logical test requires a test (does something = something) then you have a true, and false outcome.

If we dont have any data for the test, we will get no outcome.

I'm sure i must have missed something... but when you test on data which is not there, you will of course get nothing returned.

• ###### 9. Re: Cant Compare Boolean and String Values

I guess there seems to be some confusion here, "Calculation 1 " has 2 fields "Control Segment" and "Test Segment" which act as buckets where users are assigned based on some logicnto either one of them and corresponding Revenue and other measures are also assigned to them.

My point here is they do have data in them. When you create a calculated field with control segment and Test segment and drop them in the view you do get the respective Revenue for them.

Thanks

Ankit

• ###### 10. Re: Cant Compare Boolean and String Values

Hey Mark,

I got the point. Thanks got the view I wanted.

Thanks

Ankit