Qlik Community

QlikView Scripting

Discussion Board for collaboration on QlikView Scripting.

Highlighted
AH
Contributor 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

Tags (1)
1 Solution

Accepted Solutions
MVP
MVP

Re: Date with string problem

Ah, right. Probably this?

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

View solution in original post

16 Replies

Re: Date with string problem

Try this:

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

MVP
MVP

Re: Date with string problem

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
Contributor III

Re: Date with string problem

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

MVP
MVP

Re: Date with string problem

Ah, right. Probably this?

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

View solution in original post

Re: Date with string problem

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
Contributor III

Re: Date with string problem

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.

Re: Date with string problem

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

MVP
MVP

Re: Date with string problem

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.)

Re: Date with string problem

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