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: 
maohob1
Contributor II
Contributor II

Compare a value from a table to another value from another table

Hello all
I am a new user of qlik products

I have a question
I have two tables ( 'StudentTable' and 'GradeTable')

I set up a third table called 'CalculationGradeTable'

Calculates the student's score(SetMark)
Example :
If the student takes the grade of 40, he supposed to have a 'Poor' rating  Dependence on 'MinGrade, MaxGrade' field
If the student takes the grade of 88 he should have a 'very good' rating Dependence on 'MinGrade, MaxGrade' field
The valuation should be calculated with the 'SetMark' column

How to do it !!

 

// My Code ....

StudentTable:
LOAD * INLINE [
IDStd,NameStd,GradeStd
1,'A',40
2,'B',85
3,'C',75
4,'D',45
5,'E',3
6,'F',100
];


GradeTable:
LOAD * INLINE [
MinGrade, MaxGrade,Mark
0, 59 , 'Poor'
60, 75,'good'
76, 89,'very good'
90, 100,'Excellent'
];

 


CalculationGradeTable:
LOAD
IDStd as ID ,
NameStd as Name ,
IF( GradeStd >= Peek('MinGrade',0,'GradeTable') and
GradeStd <=Peek('MaxGrade',0,'GradeTable')
, Peek('Mark',0 ,'GradeTable'),
IF( GradeStd >= Peek('MinGrade',1,'GradeTable') and
GradeStd <=Peek('MaxGrade',1,'GradeTable')
, Peek('Mark',1 ,'GradeTable'),
IF( GradeStd >= Peek('MinGrade',2,'GradeTable') and
GradeStd <=Peek('MaxGrade',2,'GradeTable')
, Peek('Mark',2 ,'GradeTable'),
IF( GradeStd >= Peek('MinGrade',3,'GradeTable') and
GradeStd <=Peek('MaxGrade',3,'GradeTable')
, Peek('Mark',3 ,'GradeTable')

)))) as SetMark
Resident StudentTable
Order By GradeStd desc ;

1 Solution

Accepted Solutions
Frank_Hartmann
Master II
Master II

Maybe try like this:

StudentTable:
LOAD * INLINE [
IDStd,NameStd,GradeStd
1,'A',40
2,'B',85
3,'C',75
4,'D',45
5,'E',3
6,'F',100
];


GradeTable:
LOAD * INLINE [
MinGrade, MaxGrade,Mark
0, 59 , 'Poor'
60, 75,'good'
76, 89,'very good'
90, 100,'Excellent'
];

left Join

IntervalMatch(GradeStd)
Final:
LOAD MinGrade,MaxGrade Resident GradeTable;

View solution in original post

3 Replies
Frank_Hartmann
Master II
Master II

Maybe try like this:

StudentTable:
LOAD * INLINE [
IDStd,NameStd,GradeStd
1,'A',40
2,'B',85
3,'C',75
4,'D',45
5,'E',3
6,'F',100
];


GradeTable:
LOAD * INLINE [
MinGrade, MaxGrade,Mark
0, 59 , 'Poor'
60, 75,'good'
76, 89,'very good'
90, 100,'Excellent'
];

left Join

IntervalMatch(GradeStd)
Final:
LOAD MinGrade,MaxGrade Resident GradeTable;
maohob1
Contributor II
Contributor II
Author

Great solution.

I have a question, how can I solve the query
Using the for loop and the peek function !!
jonathandienst
Partner - Champion III
Partner - Champion III

I suggest that you use the intervalmatch solution already posted. That would normally be the correct way to solve your problem. Do you have a specific reason not to use interval matching?

Logic will get you from a to b. Imagination will take you everywhere. - A Einstein