Unlock a world of possibilities! Login now and discover the exclusive benefits awaiting you.
Hello,
I have a sales transaction table that I am loading into Qlik Sense that I need to apply two filters too. One is the year and second is the ledger code that the transactions are posted too.
Every row has a year and I only need this year's information but each row also has a GL code that the transaction is posted too and this is where I need to filter multiple options. This is code that I have tried:
FROM SysproCompanyA.dbo.ArTrnDetail
WHERE TransactionGlCode = '3000-001'
or TransactionGlCode = '3003-001'
or TransactionGlCode = '3004-001'
or TransactionGlCode = '3006-001'
or TransactionGlCode = '3007-001'
or TransactionGlCode = '3008-001'
or TransactionGlCode = '3009-001'
and GlYear = 2019;
If I use the where clause just for the GlYear it pulls in 395,000 rows. When I run the above script, it runs past this. I stopped at 700,000 rows as I knew it wasn't working correctly.
What am I doing wrong?
Hi,
Can you try using the below code.
FROM SysproCompanyA.dbo.ArTrnDetail
WHERE GlYear = 2019 and (TransactionGlCode = '3000-001'
or TransactionGlCode = '3003-001'
or TransactionGlCode = '3004-001'
or TransactionGlCode = '3006-001'
or TransactionGlCode = '3007-001'
or TransactionGlCode = '3008-001'
or TransactionGlCode = '3009-001');
Regards,
Sujay
Hi,
Can you try using the below code.
FROM SysproCompanyA.dbo.ArTrnDetail
WHERE GlYear = 2019 and (TransactionGlCode = '3000-001'
or TransactionGlCode = '3003-001'
or TransactionGlCode = '3004-001'
or TransactionGlCode = '3006-001'
or TransactionGlCode = '3007-001'
or TransactionGlCode = '3008-001'
or TransactionGlCode = '3009-001');
Regards,
Sujay
The previous post is correct -- 'And' is higher in the order of operations than 'Or', much like x is higher order than + in normal arithmetic. You need to wrap the 'Or statements in parentheses to ensure they are calculated first.
Or simplify by saying:
FROM SysproCompanyA.dbo.ArTrnDetail
WHERE
GlYear = 2019 and
TransactionGlCode In (
'3000-001',
'3003-001',
'3004-001',
'3006-001',
'3007-001',
'3008-001',
'3009-001'
);
Thanks for all the replies and the solution. Very helpful and has got me up and running.