Skip to main content
Announcements
Qlik Connect 2024! Seize endless possibilities! LEARN MORE
cancel
Showing results for 
Search instead for 
Did you mean: 
Saryk
Partner - Creator II
Partner - Creator II

Format the result of WeekName() function

Hello,

 

MonthName()'s return is formatted according to the MonthNames script variable.

Is there a similar way to format WeekName()'s return, as YYYY/WW does not suit me (I'd like something like WW-YYYY)

 

Thank you !

Labels (2)
1 Solution

Accepted Solutions
Vegar
MVP
MVP

Try this:

dual(num(Week(DateField), '00')&'-'& WeekYear(DateField), WeekName(DateField)) as WeekName

View solution in original post

6 Replies
Taoufiq_Zarra

I'll wait for the other feedback as too.
but to my knowledge there is no such formatting.

so transforms into text:

=week('12/01/2013')&'-'&year('12/01/2013')

Capture.JPG

Regards,
Taoufiq ZARRA

"Please LIKE posts and "Accept as Solution" if the provided solution is helpful "

(you can mark up to 3 "solutions") 😉
Vegar
MVP
MVP

Try this:

dual(num(Week(DateField), '00')&'-'& WeekYear(DateField), WeekName(DateField)) as WeekName

Vegar
MVP
MVP

@Taoufiq_Zarra  

I reccomend you to use yearweek() not year() when creating week names. Using Year() will give you trouble on certain dates. Consider the example below:

=week('01/01/2017')&'-'&year('01/01/2017')

Will return '52-2017' indicating it is in the end of 2017 which its not. 

 

=week('01/01/2017')&'-'&weekyear('01/01/2017')

Will return '52-2016' which is a more correct name for this date. 

Taoufiq_Zarra

@Vegar 

Well said, thank you very much.
I'm still learning 😊

Regards,
Taoufiq ZARRA

"Please LIKE posts and "Accept as Solution" if the provided solution is helpful "

(you can mark up to 3 "solutions") 😉
Vegar
MVP
MVP

@Taoufiq_Zarra 

We all are and the Qlik Community is a really good place to learn.

Thank you for contributing.

Saryk
Partner - Creator II
Partner - Creator II
Author


@Vegar wrote:

Try this:

dual(num(Week(DateField), '00')&'-'& WeekYear(DateField), WeekName(DateField)) as WeekName


I have that in some places of my scripts, but I noticed that sometimes this is being interpreted by qlik as a substraction, and gives weird results.

I just checked out what 'dual()' is, and this is brilliant. I believe it fixes the problem.

Thank you very much !