Skip to main content
Announcements
Introducing Qlik Answers: A plug-and-play, Generative AI powered RAG solution. READ ALL ABOUT IT!
cancel
Showing results for 
Search instead for 
Did you mean: 
americanetsMD
Contributor III
Contributor III

Array and loops in Qlik Sense

My task is to create a Qlik Sense script to check whether a given set of EAN (European Article Numbers) numbers have the correct check digit.
If the given EAN Number has more or less than 13 digits is to be considered invalid.
The check digit is calculated based on the following set of rules.

1. Sum all the digits in even positions and multiply by 3.
2. Add all the digits in odd positions (except for the last one, which is the check digit) to the number you’ve got in the first step.
3. Divide that number, received in the second step, by 10 and take the remainder.
4. If the remainder is not 0, subtract it from 10.

EAN Number List:
123456789012
1234567890123
9999999999999
9999999999998
4045012019462
4045012020147
4045012001375

An Example of how it's done:
the check digit calculation for EAN Number 4045012020147:

The digits in even positions are: 0, 5, 1, 0, 0, 4, their sum is 10, multiplied by 3 it is 30;
The digits in odd positions (except the last one) are: 4, 4, 0, 2, 2, 1, their sum is 13, added to the number above it is 43;
Dividing 43 by 10 gives us 3 as a remainder;
It is not zero, so subtracting it from 10 to get the check digit: 7.
The check digit is "7".

 

Could anyone please guide me in how to achieve my goal.

Labels (1)
1 Solution

Accepted Solutions
kaushiknsolanki
Partner Ambassador/MVP
Partner Ambassador/MVP

Hope this helps.

 

Data:
Load Len(EANNumberList) as Length,* inline [
EANNumberList
123456789012
1234567890123
9999999999999
9999999999998
4045012019462
4045012020147
4045012001375
];
 
Data1:
NoConcatenate
Load * Resident Data
Where Length = 13;
 
Drop table Data;
 
Data2:
Load *, If(Mod(((EvenAdd*3)+OddAdd),10)<>0,10-Mod(((EvenAdd*3)+OddAdd),10),0) as CheckNum; 
Load *,
Rangesum(Mid(EANNumberList,2,1),Mid(EANNumberList,4,1),Mid(EANNumberList,6,1),Mid(EANNumberList,8,1),Mid(EANNumberList,10,1),Mid(EANNumberList,12,1)) as EvenAdd,
Rangesum(Mid(EANNumberList,1,1),Mid(EANNumberList,3,1),Mid(EANNumberList,5,1),Mid(EANNumberList,7,1),Mid(EANNumberList,9,1),Mid(EANNumberList,11,1)) as OddAdd
Resident Data1;
 
Drop table Data1;
 
 
Please remember to hit the 'Like' button and for helpful answers and resolutions, click on the 'Accept As Solution' button. Cheers!

View solution in original post

2 Replies
kaushiknsolanki
Partner Ambassador/MVP
Partner Ambassador/MVP

Hope this helps.

 

Data:
Load Len(EANNumberList) as Length,* inline [
EANNumberList
123456789012
1234567890123
9999999999999
9999999999998
4045012019462
4045012020147
4045012001375
];
 
Data1:
NoConcatenate
Load * Resident Data
Where Length = 13;
 
Drop table Data;
 
Data2:
Load *, If(Mod(((EvenAdd*3)+OddAdd),10)<>0,10-Mod(((EvenAdd*3)+OddAdd),10),0) as CheckNum; 
Load *,
Rangesum(Mid(EANNumberList,2,1),Mid(EANNumberList,4,1),Mid(EANNumberList,6,1),Mid(EANNumberList,8,1),Mid(EANNumberList,10,1),Mid(EANNumberList,12,1)) as EvenAdd,
Rangesum(Mid(EANNumberList,1,1),Mid(EANNumberList,3,1),Mid(EANNumberList,5,1),Mid(EANNumberList,7,1),Mid(EANNumberList,9,1),Mid(EANNumberList,11,1)) as OddAdd
Resident Data1;
 
Drop table Data1;
 
 
Please remember to hit the 'Like' button and for helpful answers and resolutions, click on the 'Accept As Solution' button. Cheers!
americanetsMD
Contributor III
Contributor III
Author

Hi kaushiknsolanki,

Thank you very much for your help. It has worked to 100% and i have learned something new.

Thank you! 🙂