7 Replies Latest reply on Sep 21, 2018 7:28 AM by meenu choudhary

# Conditional arithmetic calculations

Dear Community,

I'm stuck on subtracting two values (in my current case a date difference). The challenge is that they are dates in the same field and I'd like to subtract them based on a value in another field.

I put together a rough illustration of the situation:

For example, subtracting the shipping date for Consumer from the shipping date for Corporate. Is there a way to do such a thing?

Thanks,

Mitchell

• ###### 1. Re: Conditional arithmetic calculations

Hi Mitchell,

Am I right in thinking each column there is a different record? If so you can use if statements to get the correct dates.

datediff('day',

if [Segment] = 'Consumer' then 'Ship Date' end

,

if [Segment] = 'Corporate' then 'Ship Date' end

)

• ###### 2. Re: Conditional arithmetic calculations

You're probably after the DATEDIFF function : Date Functions

That will help you get the number of periods (you can choose) between the 2 dates.

• ###### 3. Re: Conditional arithmetic calculations

Hi Mitchell,

When you say you want to subtract "Consume ship date" to "Corporate ship date" , then on what ground you want to do so.

Like there are multiple ship date for both consumer and corporate ,so how are you gonna to choose which date to pic for subtraction.

It will be nice if you can provide your expected output.

• ###### 4. Re: Conditional arithmetic calculations

Hi Chris,

They're actually in the same column though they used to be separate before I pivoted the fields.

Thanks,

Mitch

• ###### 5. Re: Conditional arithmetic calculations

Hi Meenu,

Sorry, I see I wasn't very clear there and looking at my expected output maybe what I'm asking for doesn't make a lot of sense. Below is an example of a 'unit' of my data and my expected output would be 18-7=11 days, so it would need another field at a higher level of detail to anchor to (in this case email address).

Thanks,

Mitch

• ###### 6. Re: Conditional arithmetic calculations

Hi Mitch,

If I'm understanding you correctly my calc above should work.

If not can you provide an example workbook?

• ###### 7. Re: Conditional arithmetic calculations

Hi Chris,

You can try below logic:

1. First = {Fixed [Email Address]:max( if [Login Type]="First" then [Day of login] END)}

2. Last = {Fixed [Email Address]:max( if [Login Type]="Last" then [Day of login] END)}

3. Day diff =  DATEDIFF('day',[First],[Last])