15 Replies Latest reply: Aug 14, 2015 9:35 AM by neetha P

# Using YTD field in If statement

I am trying to write an if statement in an expression using a YTD (Year to Date) field.

What I want to do is find out if the month "July" falls within the YTD field.

So something like.....If YTD contains July, then 1, else 0.  I just don't know how to make the connection on a value that isn't actually part of the yield biut is associated with it.

Steve

• ###### Re: Using YTD field in If statement

What values does your YTD field contains??

• ###### Re: Using YTD field in If statement

My YTD values are "YTD" and "NOYTD"

• ###### Re: Using YTD field in If statement

Are you asking to shift the YTD flag calculation from Jan to July Month ? or

If you already have [YTDField] in your table & we want check the YTDField in July month or not, then you can generaly IF statement like below:

IF( Month(YTDField)=7,1,0) AS YTDFlag

• ###### Re: Using YTD field in If statement

I have already identifed in the script which months are "YTD" and which months are "NOYTD". My issue is that I have an expression that I need to by able to identify specfic months in an if statement.

So I need to be able to write something along the lines of...

If YTD contains "July", then Expression 1, else expression 2

• ###### Re: Using YTD field in If statement

Can't you do this?

If(Num(Month(Today())) >= 7, Expression1, Expression2)

Where Month(Today()) will give your YTD information and 7 is used for month July

• ###### Re: Using YTD field in If statement

No because YTD is always changing. When next year comes July won't be associated with the YTD field until July comes. It needs to be dynamic.

I have 12 columns one for each month and each one needs to have this logic. THanks.

• ###### Re: Using YTD field in If statement

Why did you choose July right now? Is it the max date in your database? What was the logic?

• ###### Re: Using YTD field in If statement

July was just an example - I will need one for Jan, Feb Mar, etc. depnding on what time of the year it is. The YTD field is set to "YTD" or "NOYTD" for each month based on what time of the year it is but since the month is only associated to the YTD field and not an actual value within the field I don't know how to write expression.

• ###### Re: Using YTD field in If statement

Would you be able to share few lines of data with the expected output?? I am unable to interpret your requirement.

• ###### Re: Using YTD field in If statement

like this?

if(YTD='YTD',sum({<YTDFlag={1}>}Value),sum({<YTDFlag={0}>}Value))

• ###### Re: Using YTD field in If statement

My YTD values are "YTD" and "NOYTD"

• ###### Re: Using YTD field in If statement

Hi Zagzebski,

IF( Num(Month(YTD))= 7,1,0) AS YTDFlag

or

IF( Month(YTD)= 'JUL',1,0) AS YTDFlag

Regards

Neetha

• ###### Re: Using YTD field in If statement

Thanks Neetha - YTD  is not a month field it is only an indicator that is associated to the month field so that wouldn't work

• ###### Re: Using YTD field in If statement

I think you are looking for something along these lines. Assuming you are in a table/chart with Month* as a dimension:

=If(YTD = 'YTD', <expression 1>, <expression 2>)

The chart/table dimensions will get the appropriate values of the YTD field to enable you to choose which expression to use. This assume that the field YTD is properly associated with the field Month*.

* rename according to the month field in your application.

• ###### Re: Using YTD field in If statement

Hi,