4 Replies Latest reply on Mar 8, 2016 4:12 PM by Shivang Desai

# Incrementing by 1 to a substring fetched

Hi all,

I am trying to apply increment logic to the substring fetched.

So in the above diagram,

The 3 graphs are for years 2013,14,15 and the dot is for 2016

I am basically trying to shift that dot to week 2

So I have a condition which says if the financial year = 2016 then increment my week 1 to week 2, so that dot is shifted.

Week 01 , 02 ... 12   is a string and I need to add increment to the substring fetched (01 + 1 ) = Week 02

My current logic is as follows:

IF [Date_FiNancial_Year] = "2016/17" THEN "Week" + RIGHT([Date_Financial_Week],2) + 1  ELSE ([Date_Financial Week]) END

I am getting an error because of +1 , how can I solve this?

• ###### 1. Re: Incrementing by 1 to a substring fetched

Shivang:

The error is due to adding string (ex. 01) and a number. System cannot add numbers and strings. To get this working you have to get the number from the string and add + 1 and convert back to string, so you can retain 01, 02...

This should solve it;

right("00" + str(int(RIGHT([Date_Financial_Week],2)) + 1), 2)

Let me explain

// get the right 2 chars

RIGHT([Date_Financial_Week],2)

// convert to integer

int(RIGHT([Date_Financial_Week],2))

//create string .. the integer will become string

str(int(RIGHT([Date_Financial_Week],2)) + 1)

// so you can add 00 to it

"00" + str(int(RIGHT([Date_Financial_Week],2)) + 1)

// now get right 2 chars so you preserve 0 as the prefix for a single digit

right("00" + str(int(RIGHT([Date_Financial_Week],2)) + 1), 2)

Hope this works..

..kk

1 of 1 people found this helpful
• ###### 2. Re: Incrementing by 1 to a substring fetched

Amazing logic my friend!

It worked like a charm..

Regards,

Shivang Desai

• ###### 4. Re: Incrementing by 1 to a substring fetched

Hi,

A quick doubt. Why is the blue line as you see in the above graph is appearing at the current week? So again for Week 2, the blue line will be shifted to Week 02.

I tried a lot of formatting options but it doesn't go.

Any thoughts on it?

Regards,

Shivang Desai