Bring your best ideas to the AI Use Case Contest! Enter to win 40 hours of expert engineering support and bring your vision to life using the powerful combination of Alteryx + AI. Learn more now, or go straight to the submission form.
Start Free Trial

Alteryx Designer Desktop Discussions

Find answers, ask questions, and share expertise about Alteryx Designer Desktop and Intelligence Suite.
SOLVED

Week as range for the filter if condition is met.

soncoku
9 - Comet

I have this code which gets the current week as range for the Filter Tool. From Monday to Sunday (dates)

I want it to also check if it's Monday when ever I run the workflow. If it is Monday then the range for the filter should be Monday - Sunday of the past week.

If it's not Monday it should work as it is and get this week as range.

 

Any guesses?

 

 

DateTimeTrim([DATE],'days') >=
DateTimeTrim(
DateTimeAdd(
DateTimeTrim(DateTimeNow(),'year')
,8-ToNumber(DateTimeFormat(DateTimeTrim(DateTimeNow(),'year'),'%u')) +
(ToNumber(DateTimeFormat(DateTimeNow(),'%W'))-1)*7
,'days')
,'days')
AND
DateTimeTrim([DATE],'days') <=
DateTimeTrim(
DateTimeAdd(
DateTimeTrim(DateTimeNow(),'year')
,8-ToNumber(DateTimeFormat(DateTimeTrim(DateTimeNow(),'year'),'%u')) +
(ToNumber(DateTimeFormat(DateTimeNow(),'%W'))-1)*7 +
6
,'days')
,'days')

 



1 REPLY 1
soncoku
9 - Comet

Solved by:  @RolandSchubert  

DateTimeTrim([DATE],'days') >=
DateTimeTrim(
DateTimeAdd(
DateTimeTrim(DateTimeAdd(DateTimeNow(), DateTimeFormat(DateTimeNow(), '%u') = '1', 'day'),'year')
,8-ToNumber(DateTimeFormat(DateTimeTrim(DateTimeAdd(DateTimeNow(), DateTimeFormat(DateTimeNow(), '%u') = '1', 'day'),'year'),'%u')) +
(ToNumber(DateTimeFormat(DateTimeAdd(DateTimeNow(), DateTimeFormat(DateTimeNow(), '%u') = '1', 'day'),'%W'))-1)*7
,'days')
,'days')
AND
DateTimeTrim([DATE],'days') <=
DateTimeTrim(
DateTimeAdd(
DateTimeTrim(DateTimeAdd(DateTimeNow(), DateTimeFormat(DateTimeNow(), '%u') = '1', 'day'),'year')
,8-ToNumber(DateTimeFormat(DateTimeTrim(DateTimeAdd(DateTimeNow(), DateTimeFormat(DateTimeNow(), '%u') = '1', 'day'),'year'),'%u')) +
(ToNumber(DateTimeFormat(DateTimeAdd(DateTimeNow(), DateTimeFormat(DateTimeNow(), '%u') = '1', 'day'),'%W'))-1)*7 +
6
,'days')
,'days')

 

Labels
Top Solution Authors