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: 
Larsstoel
Contributor II
Contributor II

Sorting day names based on today's day

I am looking for an expression that allows me to sort a table based on today's day.

I have a table named Monday, Tuesday, Wednesday, Thursday and Friday. If today is Wednesday the order will have to be Wednesday Thursday Friday Saturday Sunday Monday Tuesday. and if it is Friday the order will have to be Friday Saturday Sunday Monday Tuesday Wednesday Thursday.
How can I write this expression?

Thanks in advance!

Labels (2)
1 Solution

Accepted Solutions
MayilVahanan

Hi

Create a field in backend for shorting and use that field in custom sort .

Load *, Pick(Match(WKDay, Today, T_1, T_2, T_3, T_4, T_5)+1, 7, 1,2,3,4,5,6) as DayShort;
Load *, Left(Day, 3) as WKDay, WeekDay(Today()) as Today, WeekDay(Today()-1) as T_1 , WeekDay(Today()-2) as T_2 , WeekDay(Today()-3) as T_3 , WeekDay(Today()-4) as T_4 , WeekDay(Today()-5) as T_5 Inline
[
Day
Monday
Tuesday
Wednesday
Thursday
Friday
Saturday
Sunday
];
Drop Field Today, T_1, T_2, T_3, T_4, T_5;

Ex: We can use DayShort is the field used to sort the dimension. 

Thanks & Regards, Mayil Vahanan R
Please close the thread by marking correct answer & give likes if you like the post.

View solution in original post

2 Replies
MayilVahanan

Hi

Create a field in backend for shorting and use that field in custom sort .

Load *, Pick(Match(WKDay, Today, T_1, T_2, T_3, T_4, T_5)+1, 7, 1,2,3,4,5,6) as DayShort;
Load *, Left(Day, 3) as WKDay, WeekDay(Today()) as Today, WeekDay(Today()-1) as T_1 , WeekDay(Today()-2) as T_2 , WeekDay(Today()-3) as T_3 , WeekDay(Today()-4) as T_4 , WeekDay(Today()-5) as T_5 Inline
[
Day
Monday
Tuesday
Wednesday
Thursday
Friday
Saturday
Sunday
];
Drop Field Today, T_1, T_2, T_3, T_4, T_5;

Ex: We can use DayShort is the field used to sort the dimension. 

Thanks & Regards, Mayil Vahanan R
Please close the thread by marking correct answer & give likes if you like the post.
Vegar
MVP
MVP

You could try something like this.

Dual( 

  date(datefield, 'WWWW'), 

  weekday(datefield , weekday(today()))

)