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

Sorting order by expression for today() function

Hi all,

So I am looking for a different way to order weekdays. I want the weekday of today to be the first in a barchart. Today is a friday for example, so I want the figure to display: fri - sat - sun - mon - tue - wed - thu.

This is what I am currently trying, but it gives a wrong, random order:

=IF(weekday([datefield])=weekday(today()),1,

IF(weekday([datefield])=weekday(today()+1),2,

  IF(weekday([datefield])=WeekDay(today()+2),3,

   IF(weekday([datefield])=weekday(today()+3),4,

    IF(weekday([datefield])=weekday(today()+4),5,

     IF(weekday([datefield])=weekday(today()+5),6,7))))))

I'm looking forward to seeing your solutions! Thanks in advance.

Labels (1)
3 Replies
mikaelsc
Specialist
Specialist

Hi Bart,

the most simple/clean would be, i guess, to change this variable in the load script:  (this of course means it will be applied everywhere in your app)

SET FirstWeekDay=0;

change that to: SET FirstWeekDay=4;

https://help.qlik.com/en-US/sense/June2018/Subsystems/Hub/Content/Scripting/NumberInterpretationVari...

so when sorting your days, you'll get fridays first:

https://help.qlik.com/en-US/sense/June2018/Subsystems/Hub/Content/Scripting/DateAndTimeFunctions/wee...

mikaelsc
Specialist
Specialist

ow and if you want that to be "dynamic" per reload day,

let FirstWeekDay= weekday(today());

thakkarrahul01
Creator
Creator

You can add Week Sort Order column in your table where you will specify incremental number for each weekday and add  that sort order using new derived column in chart properties as required. Sorting weight for today will be required to be calculated assuming your app is refreshed on daily basis.


This should give you custome sort option.

Régards,

Rahul