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

Announcements
Qlik GA: Multivariate Time Series in Qlik Predict: Get Details
cancel
Showing results for 
Search instead for 
Did you mean: 
Peony
Creator III
Creator III

Apply calculation in Inline Table

Hi All

I face a difficulty with how to bring calculation into inline table and then how to use it as measure within table object. The idea is to take fields from DB table (in example below it is a "Numbers" table). And then in inline table "Test" create several dimetions and associate them with particular calculations. I need to do this to have possibility sow in pivot table different calculations aggregated by created dims.
But as long as I tried I have no luck with how to specify calculation correctly within "Test" table and then use them ad measure within pivot to achieve  calculation results. I will appreciate any hint regarding this.   

Numbers:
Load* Inline [
F1, F2
1, 4
2, 5
3, 6
];

test:
LOAD * INLINE [

ParentLevel, ChildLevel, Calculation

'Total', 'First', 'Sum(F1)'

'Total', 'Second', 'Sum(F2)'

'Total', 'Third', 'Sum(F1-F2)'

'Row', 'Row High', 'Sum(F1)-20'

'Row', 'Row Low', 'Avg(F2)'
];

Labels (5)
1 Solution

Accepted Solutions
lblumenfeld
Partner Ambassador
Partner Ambassador

I think this code snippet does what you've indicated.

 

Numbers:
Load
	Sum(F1) as Sum_F1,
    Sum(F2) as Sum_F2,
    Avg(F2) as Avg_F2
Inline [
F1, F2
1, 4
2, 5
3, 6
];

test:
Load
	ParentLevel, 
    ChildLevel,
    Evaluate(Calculation)
Inline
[
ParentLevel, ChildLevel, Calculation
Total, First, "Peek('Sum_F1',0,'Numbers')"
Total, Second, "Peek('Sum_F2',0,'Numbers')"
Total, Third, "Peek('Sum_F1',0,'Numbers')-Peek('Sum_F2',0,'Numbers')"
Row, Row High, "Peek('Sum_F1',0,'Numbers')-20"
Row, Row Low, "Peek('Avg_F2',0,'Numbers')"
];

 

View solution in original post

6 Replies
pravinboniface
Creator III
Creator III

@Peony I am not sure I understand fully, but can't you just define variables for the calculations? 

You can then use the variables in the UI as needed.

Peony
Creator III
Creator III
Author

@pravinboniface I'm afraid onse I will associate particular dimension with particular variable inside table object using 'IF' condition this will overload UI with calculation. So I hope to find a way to associate dims and calculation within load script

lblumenfeld
Partner Ambassador
Partner Ambassador

I think this code snippet does what you've indicated.

 

Numbers:
Load
	Sum(F1) as Sum_F1,
    Sum(F2) as Sum_F2,
    Avg(F2) as Avg_F2
Inline [
F1, F2
1, 4
2, 5
3, 6
];

test:
Load
	ParentLevel, 
    ChildLevel,
    Evaluate(Calculation)
Inline
[
ParentLevel, ChildLevel, Calculation
Total, First, "Peek('Sum_F1',0,'Numbers')"
Total, Second, "Peek('Sum_F2',0,'Numbers')"
Total, Third, "Peek('Sum_F1',0,'Numbers')-Peek('Sum_F2',0,'Numbers')"
Row, Row High, "Peek('Sum_F1',0,'Numbers')-20"
Row, Row Low, "Peek('Avg_F2',0,'Numbers')"
];

 

eddyvargas
Contributor III
Contributor III

I dont know if is the best solution but works the expression:

$(=Concat('If(Calculation='''&Calculation&''','&Calculation,',')&Repeat(')',Count(Calculation)))

 

If your expressions have dollar function you need to create variables in script replacing with other characters like:

Replace('$(_vExp)','!@#%',Chr(36))

Peony
Creator III
Creator III
Author

@lblumenfeld Thank you for help. Your idea works perfectly well!