Do not input private or sensitive data. View Qlik Privacy & Cookie Policy.
Skip to main content
Announcements
WEBINAR June 25, 2025: Build on Apache Iceberg with Qlik Open Lakehouse - REGISTER TODAY
cancel
Showing results for 
Search instead for 
Did you mean: 
emilyrabbit
Creator
Creator

selection error

HI ,

I want to compare the selection year's order amount with the selection year-1 order amount.

So, I use below variable:

v_maxyear_order=if(max([Order Year])<=year(today()),max([Order Year]),year(today()))

emilyrabbit_0-1748959585072.png

v_lastyear_order=v_maxyear_order-1

emilyrabbit_1-1748959631430.png

 

and in the kpi:

select year=Count(
{
$<[Order Year]={$(v_maxyear_order)}
,[Order Purchase Order Number]={"=not WildMatch([Order Purchase Order Number],'*TQBH*')"}
>
}
DISTINCT [Order Document Number])

emilyrabbit_2-1748834456667.png

select year-1=Count(
{
$<[Order Year]={$(v_lastyear_order)},
[Order Purchase Order Number]={"=not WildMatch([Order Purchase Order Number],'*TQBH*')"}
>
}
DISTINCT [Order Document Number])

emilyrabbit_3-1748834504421.png

the weird thing happens:

if I choose [order year]=2025, we can see the select year=6532 (current select year=2025), and the select year-1(current select year-1 should be 2024)=50

emilyrabbit_0-1748834226915.png

if I check [select year-1],below is the expression: it seems ok ,but the [select year-1] (should be 2024's result is not ok)

emilyrabbit_3-1748959887241.png

 

 

 

if if I choose [order year]=2024, we can see the select year(current select year=2024)=14548 , and the select year-1(current select year-1 should be 2023)=140

emilyrabbit_1-1748834343495.png

if I remove the  [order year] selection , the result is good.

emilyrabbit_2-1748959787233.png

 

I am curious , and the 2024 order should be 14 548. why?

Labels (5)
1 Solution

Accepted Solutions
Oleg_Troyansky
Partner Ambassador/MVP
Partner Ambassador/MVP

Hi Emily,

I checked the screenshots, and I realize that my initial guess was incorrect - your variables work as expected.

I think the issue is in the "conflict" between the selected "Order Year" and the two Set Analysis Filters, one of them also being "Order Year".

So, your first filter [Order Year]={$(v_lastyear_order)} is replacing the selected year with the calculated  value from the variable. So far so good.

The second filter uses an Advanced Search (aka "expression search") - that is a "strange animal". In essence, it contains its own aggregation with its own Set Analysis that doesn't necessarily follows the selection from your first filter. So, while the first filter may be selecting year 2024, the second filter could be working with a data set where the selected year is 2025. Surprisingly, the result is not zero, but I'd need to dig deep into your data to understand why us that.

So your solution could be one of the following - either equip your advanced search with a proper Set Analysis of its own, or replace Advanced Search with a simple search. I'd try something like this:

 

{
$<[Order Year]={$(v_lastyear_order)},
[Order Purchase Order Number]-={"*TQBH*"}
 >}

This is a simple search, and it doesn't carry the same issues as the advanced search. I remember from your earlier questions that you were trying to make this selection ignore upper/lower case, and that's what wildmatch was used for. Try using a field on the fly instead:

{
$<[Order Year]={$(v_lastyear_order)},
"=UPPER([Order Purchase Order Number])" -={"*TQBH*"}
 >}

Cheers,

Oleg

 

 

View solution in original post

16 Replies
Oleg_Troyansky
Partner Ambassador/MVP
Partner Ambassador/MVP

Hi Emily,

It appears to me that your variables may not be working as expected. To help me diagnose, can you please share a few more screenshots:

- the definitions and the values of both variables (especially the previous year) from the variable overview.

- the full view of the Expression Editor for the Prior Year expression, when either 2024 or 2025 is selected as the current year.

Cheers,

Oleg Troyansky

Aditya_Chitale
Specialist
Specialist

@emilyrabbit ,

If you are analyzing the variables in a KPI, have you tried changing the number formatting to Measure Expression in the KPI options ? Also, when creating the variable v_lastyear_order,  add a $ sign before the variable v_maxyear_order

something like: 

v_lastyear_order=$(v_maxyear_order)-1

Let me know if the suggestions worked.

Regards,

Aditya

emilyrabbit
Creator
Creator
Author

HI ,I have attached more screenshot ,could you pls check?

emilyrabbit
Creator
Creator
Author

emilyrabbit_0-1748960135910.png

HI I have tried, but the result is still wrong.

emilyrabbit_1-1748960161181.png

 

lennart_mo
Creator
Creator

Hi @emilyrabbit,

I think the problem lies in the second part of your set expression:

[Order Purchase Order Number]={"=not WildMatch([Order Purchase Order Number],'*TQBH*')"}

The Wildmatch seems to only use the [Order Purchase Order Number] Values available for the current selection. Adding '{<[Order Year]=>}' as follows should work.

[Order Purchase Order Number]={"= {<[Order Year]=>} not WildMatch([Order Purchase Order Number],'*TQBH*')"}

Hope this helps!

Regards,

Lennart

 

emilyrabbit
Creator
Creator
Author

Hi ,I have added some screenshot in the question. could you pls help checking it ? Thanks.

emilyrabbit
Creator
Creator
Author

HI Lennart , nice to meet you .I am very interested on your logic. because normally, 

{
$<[Order Year]={$(v_lastyear_order)},
[Order Purchase Order Number]={"=not WildMatch([Order Purchase Order Number],'*TQBH*')"}

part1 and part2 is dependent. Can you pls explain it more detail ? I really want to understand them clearly and more. Thanks so much.

lennart_mo
Creator
Creator

Hi Emily, 

While part1 and part2 do depend on each other, the expressions setting the values should only be affected by the applied selections. 

I think in this case it's easier to understand looking at the first expression. Were you to set the Order Number via the set analysis, to a value only occuring in 2024, v_maxyear_order should still evaluate to 2025 in the same set expression. 

On the other hand, were you to actually select the same Order Number, v_maxyear_order should now return 2024.

rafaelencinas
Partner - Creator
Partner - Creator

Hi @emilyrabbit !

It could be a little bit simple..

Orders:
LOAD *
, Year("Order Data") as "Order Year"
;
Load * INLINE [
Order Purchase Order Number | Order Data | Order Document Number
ABC123 | 01/01/2024 | ABC123
ABC354 | 01/01/2025 | ABC354
ABC356 | 01/01/2025 | ABC356
TQBH123 | 01/01/2024 | TQBH123
TQBH354 | 01/01/2025 | TQBH354
](delimiter is '|');

 

Actual Year

Count({
$<[Order Year]={"$(=Max([Order Year]))"}
,[Order Purchase Order Number] -={"*TQBH*"} >}
DISTINCT [Order Document Number])

 

Last Year

Count({
$<[Order Year]={"$(=Max([Order Year])-1)"}
,[Order Purchase Order Number] -={"*TQBH*"} >}
DISTINCT [Order Document Number])

 

rafaelencinas_0-1749063046966.png

 

Bye!

 

 

 

 

 

 

Senior Qlik Architect
Cobra, Stallone, "You're a problem and I'm the solution"