Do not input private or sensitive data. View Qlik Privacy & Cookie Policy.
Skip to main content

Announcements
Join us in Toronto Sept 9th for Qlik's AI Reality Tour! Register Now
cancel
Showing results for 
Search instead for 
Did you mean: 
GeorgeKokkinopoulos
Contributor II
Contributor II

Trying to create a date variable using Load Inline. Variable doesn't work in Set Analysis

Hello,

I am using this code in Data load editor:

LOAD IF(week_number=1,date(today(),'DD-MMM-YY'),date(today()+7,'DD-MMM-YY')) as vWeekField,

* INLINE [ week_number
1
2
];

My purpose is to create a new field named vWeekField with two values (today and a week from now) and then create a measure using set analysis that contains this field:

count(distinct{<DATE_FIELD1 = {">$(=(date(vWeekField,'YYYY-MM-DD HH:MM:SS.000000')))"}>} Part_Number)

It seems that  my Set Analysis above doesn't recognise 'vWeekField' as a variable nor can I find it in my variables list. I am able to create a line graph using vWeekField as the x-Axis but the measure doesn't work as my y-Axis.

Any ideas?

Thanks

George

Labels (2)
1 Solution

Accepted Solutions
Or
MVP
MVP

vWeekField isn't a variable, it's a field. Because it contains two different vales, when you use it directly in your set analysis, it can't pick one or the other and the result is null.

Because I'm not sure what you're trying to achieve exactly, I'm not sure what the correct approach is - perhaps to create two fields or two variables (which are created in script using SET or LET statements) and use whichever one you want in the set analysis, or perhaps you're looking for a field where the user selects the week in which case your code won't work unless a single value is selected in that field.

View solution in original post

3 Replies
Or
MVP
MVP

vWeekField isn't a variable, it's a field. Because it contains two different vales, when you use it directly in your set analysis, it can't pick one or the other and the result is null.

Because I'm not sure what you're trying to achieve exactly, I'm not sure what the correct approach is - perhaps to create two fields or two variables (which are created in script using SET or LET statements) and use whichever one you want in the set analysis, or perhaps you're looking for a field where the user selects the week in which case your code won't work unless a single value is selected in that field.

kimtimz12
Contributor
Contributor

Dynamic Set Analysis From Inline Table Values ... You can try to create this expression as variable in your script, using your table as ...https://hardees-breakfast-menu.info/ 

GeorgeKokkinopoulos
Contributor II
Contributor II
Author

Hi Or,

Thanks for your reply. Actually, I was trying to create a line graph where the x-Axis is this vWeekField field I created so trying to use Set Analysis wasn't the proper approach. I have now created my measure using that:

count(distinct IF(DATE_FIELD1 > vWeekField, Part_Number))

and it worked fine. As your comment directed me to the right approach I will accept it as solution.

Many thanks

George