Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 
Anonymous
Not applicable

Could anyone help me with my If and Wildmatch script

Hello everyone,

Please help me with my script I am new to QlikView.

I need to compare the Weekday today.

If WeekDay(Today()) = 'Tuesday' is true (7-3)+2 if not 0

If ((WildMatch(WeekDay(Today()), '*Sunday*'))=1, (7-1)+2, 0)

elseIf ((WildMatch(WeekDay(Today()), '*Monday*'))=1, (7-2)+2, 0)

elseIf ((WildMatch(WeekDay(Today()), '*Tuesday*'))=1, (7-3)+2, 0)

elseIf ((WildMatch(WeekDay(Today()), '*Wednesday*'))=1, (7-4)+2, 0)

elseIf ((WildMatch(WeekDay(Today()), '*Thursday*'))=1, (7-5)+2, 0)

elseIf ((WildMatch(WeekDay(Today()), '*Friday*'))=1, (7-6)+2, 0)

elseIf ((WildMatch(WeekDay(Today()), '*Saturday*'))=1, (7-7)+2, 0)

endif


I do not know if im doing it right.

1 Solution

Accepted Solutions
Anonymous
Not applicable
Author

What are you trying to achieve as there may be a simpler way that the community can help you discover.

From what I can understand you are trying to do a specific calculation based on the day of the week. The below is a solution for what you have above.

=if(WeekDay(today(1))='Mon',(7-2)+2,

if(WeekDay(today(1))='Tue',(7-3)+2,

if(WeekDay(today(1))='Wed',(7-4)+2,

if(WeekDay(today(1))='Thu',(7-5)+2,

if(WeekDay(today(1))='Fri',(7-6)+2,

if(WeekDay(today(1))='Sat',(7-7)+2,

if(WeekDay(today(1))='Sun',(7-1)+2,0)))))))

Breakdown:

"If" statement will evaluate the output of "WeekDay(today(1))" and give either the correct calculation or the will re-evaluate until it has cycled through all the days of the week.


WeekDay() - Weekday will find what the weekday is base on the date "Today(1)"


(Today(0) = Date document was loaded,  DateToday(1) = Current Date, Today(2) or Today() = Date the document was opened)


View solution in original post

5 Replies
Anonymous
Not applicable
Author

What are you trying to achieve as there may be a simpler way that the community can help you discover.

From what I can understand you are trying to do a specific calculation based on the day of the week. The below is a solution for what you have above.

=if(WeekDay(today(1))='Mon',(7-2)+2,

if(WeekDay(today(1))='Tue',(7-3)+2,

if(WeekDay(today(1))='Wed',(7-4)+2,

if(WeekDay(today(1))='Thu',(7-5)+2,

if(WeekDay(today(1))='Fri',(7-6)+2,

if(WeekDay(today(1))='Sat',(7-7)+2,

if(WeekDay(today(1))='Sun',(7-1)+2,0)))))))

Breakdown:

"If" statement will evaluate the output of "WeekDay(today(1))" and give either the correct calculation or the will re-evaluate until it has cycled through all the days of the week.


WeekDay() - Weekday will find what the weekday is base on the date "Today(1)"


(Today(0) = Date document was loaded,  DateToday(1) = Current Date, Today(2) or Today() = Date the document was opened)


Anil_Babu_Samineni

Your condition won't give because WeekDay() returns short day names. Can you use this?

If(WildMatch(Date(Today(), 'WWWW'), '*Sunday*')=1, (7-1)+2,

If(WildMatch(Date(Today(), 'WWWW'), '*Monday*')=1, (7-2)+2,

If(WildMatch(Date(Today(), 'WWWW'), '*Tuesday*')=1, (7-3)+2,

If(WildMatch(Date(Today(), 'WWWW'), '*Wednesday*')=1, (7-4)+2,

If(WildMatch(Date(Today(), 'WWWW'), '*Thursday*')=1, (7-5)+2,

If(WildMatch(Date(Today(), 'WWWW'), '*Friday*')=1, (7-6)+2,

If(WildMatch(Date(Today(), 'WWWW'), '*Saturday*')=1, (7-7)+2, 0)))))))

Best Anil, When applicable please mark the correct/appropriate replies as "solution" (you can mark up to 3 "solutions". Please LIKE threads if the provided solution is helpful
effinty2112
Master
Master

Hi Cherry,

Try:

8-num(Weekday(Today(),6))

cheers

Andrew

sunny_talwar

Don't see the point of using a if not 0 because Today will always be one of the 7 days possible... so keeping that in mind, may be this (assuming you have this in your environmental variables SET FirstWeekDay=6;)

Pick(Num(WeekDay(Today())), ((7-2)+2), ((7-3)+2), ((7-4)+2), ((7-5)+2), ((7-6)+2), ((7-7)+2), ((7-1)+2))

or why even do the calculation?

Pick(Num(WeekDay(Today())), 7, 6, 5, 4, 3, 2, 8)

Anonymous
Not applicable
Author

Hello everyone,

Thanks for the help and for giving other options on how I could execute the script. It is much appreciated.

Regards,

Cherry