Skip to main content
Announcements
Have questions about Qlik Connect? Join us live on April 10th, at 11 AM ET: SIGN UP NOW
cancel
Showing results for 
Search instead for 
Did you mean: 
AH
Creator III
Creator III

Date with string problem

Hi,

I have a Month column that contains Months value Like this 'January', 'February' and so on. I have a Year field that contains Year Value Like this '2014', '2015' and so on.

I would like to tie this two column and make a date field and then calculate the max date from this field.

The problem is when i concatenate this two field and make one date field i cant calculate max date from that date field. I think the reason behind is, i am concatenating string and number.

Could anyone help me out this problem?

Thanks,

Ahmed100

1 Solution

Accepted Solutions
johnw
Champion III
Champion III

Ah, right. Probably this?

date(max([Month Year],'MMM YYYY')

View solution in original post

16 Replies
sunny_talwar

Try this:

MakeDate(YearField, Num(Month(Date#(MonthField, 'MMMM'))), 1) as Date

johnw
Champion III
Champion III

I don't think being a number would stop the concatenation. Works fine for me like this:

date#('February ' & 2015,'MMMM YYYY')

So in the script, I'd do something like this:

,date#([Month] & ' ' & [Year],'MMMM YYYY') as [Month Year]

And then just this as the expression:

max([Month Year])

edit: date(max([Month Year],'MMM YYYY')

AH
Creator III
Creator III
Author

Hi John, Thanks a lot!

While calculating the max i am getting integer value but if i use date function before max then i am getting date format like this 1/1/2016. but i would like to keep it like Jan 2016.

Thanks again.

Regards,

Ahmed100

johnw
Champion III
Champion III

Ah, right. Probably this?

date(max([Month Year],'MMM YYYY')

sunny_talwar

Here is a sample to play around with:

SET LongMonthNames='January;February;March;April;May;June;July;August;September;October;November;December';

Table:

LOAD *,

  MonthName(Date) as MonthYear;

LOAD *,

  MakeDate(Year, Num(Month(Date#(Month, 'MMMM'))), 1) as Date;

LOAD * Inline [

Year, Month, Sales

2014, January, 343

2014, February, 420

2014, March, 492

2014, April, 234

2014, May, 542

2014, June, 432

2014, July, 654

2014, August, 234

2014, September, 323

2014, October, 653

2014, November, 653

2014, December, 658

];

Capture.PNG

AH
Creator III
Creator III
Author

Hi Sunny, for some reason your solution didnt show up before Johns post! . I dont know what happened.

But thank you so much for your help. You have been very helpful before as well.

sunny_talwar

As long as you get to what you are looking for, we don't mind who get the right answer. If you still feel my answer is useful, you can mark it as a helpful answer (but you don't have to)

Qlik Community Tip: Marking Replies as Correct or Helpful

johnw
Champion III
Champion III

Yeah, strange, I didn't see it before I posted either, or even after I posted for quite some time.

(edit: Ah, the forum updates the time when I update the message.)

sunny_talwar

It popped up from no where? Strange, I was not even put for moderation