Skip to main content
Woohoo! Qlik Community has won “Best in Class Community” in the 2024 Khoros Kudos awards!
Announcements
Nov. 20th, Qlik Insider - Lakehouses: Driving the Future of Data & AI - PICK A SESSION
cancel
Showing results for 
Search instead for 
Did you mean: 
jan2
Contributor
Contributor

Creating a new column in the script

Hi,

I have a large data set in which a column with a date exists (format: dd.mm.yyyy). Now I need to create an extra column which shows the respective calendar week and year. I want to implement that in the script. 

I hope someone can help me. 

Labels (3)
2 Solutions

Accepted Solutions
micheledenardi
Specialist II
Specialist II

Alternatively you can use WeekName() to get week number e year in YYYY/WW format:

WeekName(YourDateTimeField) as YearWeek
Michele De Nardi
If a post helps to resolve your issue, please accept it as a Solution.

View solution in original post

micheledenardi
Specialist II
Specialist II

[Table Name]:
Load
Data1,
WeekName(Data1) as [YearWeek Data1],
Data2,
WeekName(Data2) as [YearWeek Data2],
Data3,
WeekName(Data3) as [YearWeek Data3]
From[Data Source]

CONCATENATE (Table Name)
Load
Data 1,
WeekName([Data 1]) as [YearWeek Data 1],
Data 2,
WeekName([Data 2]) as [YearWeek Data 2],
Data 3,
WeekName([Data 3]) as [YearWeek Data 3]
From[Data Source]

Store[]
Michele De Nardi
If a post helps to resolve your issue, please accept it as a Solution.

View solution in original post

10 Replies
micheledenardi
Specialist II
Specialist II

Use Week() and Year() functions to build something like:

Load *,
week(YourDateTimeField)&'/'&Year(YourDateTimeField) as WeekYear
From YourDataSource;
Michele De Nardi
If a post helps to resolve your issue, please accept it as a Solution.
jan2
Contributor
Contributor
Author

Thanks, is that also possible when a time is included? Format: "yyyy-mm-dd hh-mm-sec" as you see in the attachment?

Or is there another command that I can use?

micheledenardi
Specialist II
Specialist II

Yes, it works in that case as well:

2021-01-27 13_06_46-test - My new sheet (47) _ Sheet - Qlik Sense.png

 

Michele De Nardi
If a post helps to resolve your issue, please accept it as a Solution.
jan2
Contributor
Contributor
Author

It worked, thanks. But that leads me to the next problem. The first three days of 2021 are labeled as calender week 53. So if I combine week() and year () I get 53/2021. Any idea how I could fix that?

micheledenardi
Specialist II
Specialist II

You can fix this bug by replace the expression with this:

week(YourDateTimeField)&'/'&Year(WeekStart(YourDateTimeField)) as WeekYear
Michele De Nardi
If a post helps to resolve your issue, please accept it as a Solution.
micheledenardi
Specialist II
Specialist II

Alternatively you can use WeekName() to get week number e year in YYYY/WW format:

WeekName(YourDateTimeField) as YearWeek
Michele De Nardi
If a post helps to resolve your issue, please accept it as a Solution.
jan2
Contributor
Contributor
Author

If I try this the first days of 2020 are displayed as 2019.

micheledenardi
Specialist II
Specialist II

please post some example data

Michele De Nardi
If a post helps to resolve your issue, please accept it as a Solution.
jan2
Contributor
Contributor
Author

At what place do I have to put it in the script? At the moment it looks like:

[Table Name]:

Load

Data1,

Data2,

Data3

From[Data Source]

CONCATENATE (Table Name)

Load

Data 1,

Data 2,

Data 3

From[Data Source]

Store[]