IF ELSE with conditions

Hi all,
I’m new in Quicksight. I am trying to add conditions in the if else statment, but I am getting the error. Can you guys let me know how this can be fixed.

ifelse({container_id}=#0, {close_time}-{stage_time}, {event_time}-{staging_time})

Basically I want to create a new column where the calculation depends on whether the container ID column contains “#0” or not. If it does, I’d subtract close time from stage time; if it doesn’t, I’d subtract event time from staging time.

1 Like

Hello @cijod, just to clarify, would your container_id value have multiple numbers but you just want to check if it has a 0, or are you wanting to check if it is the number 0? I’ll write an option for both just in case.

Contains 0 = ifelse(contains(toString({container_id}), '0'), {close_time}-{stage_time}, {event_time}-{staging_time})

Equals 0 = ifelse({container_id} = 0, {close_time}-{stage_time}, {event_time}-{staging_time})

In order to use the contains function in Quick Sight, the value being checked needs to be a string. So you can convert the value to a string, check for a 0, then return the expected value. Otherwise, if you want to check if it equals a number, you can use the 2nd calculation.

I’ll mark my response as the solution, but please let me know if you have any follow-up questions. Thank you!

1 Like

Thank you so much Dylan. The container ID was a string, and I made some change in the first query that you have provided and it worked.

Thanks :slight_smile:

1 Like