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

Announcements
Join us in Toronto Sept 9th for Qlik's AI Reality Tour! Register Now
cancel
Showing results for 
Search instead for 
Did you mean: 
chhavi376
Creator II
Creator II

Using Text as Field in Sum function

Hi All,

I cannot share the QV file but i am explaining a scenario where i am stuck.

There is one field in the data:

TYPE

c1

c2

c3

c4

ANd there is another table in my data like:

c1    c2    c3    c4

1      1        0        1

1      0        1        1

I want a table(on UI) like:

Type          sum()

c1            2

c2            1

c3            1

c4            2


So i am trying to use SUM(fieldvalue('Type',RowNo)) function to get the sum. The problem is that QV is not able to identify that the return value of fieldvalue() function is a column name.

21 Replies
chhavi376
Creator II
Creator II
Author

You are a savior!

chhavi376
Creator II
Creator II
Author

Hi Tresesco,

Your expression worked perfectly for me.

But there is another addition which is required now.

they want the sum where type=1 for that particular type..

if we are calculating sum for say, c1, instead of sum(c1) it should be sum({<c1={1}>}c1).. for c2,  sum({<c2={1}>}c2).  same for c3, c4 and so on

I avoided creating another discussion because it would lead to confusion.

Can you please help me in the same?

Regards,

Chhavi

chhavi376
Creator II
Creator II
Author

Tresesco.. can you help?

tresesco
MVP
MVP

Is this specific to C1 only or applicable to all cases?

chhavi376
Creator II
Creator II
Author

All cases.

Something like this:

c1   sum({<c1={1}>}c1)..

c2   sum({<c2={1}>}c2)..

c3   sum({<c3={1}>}c3)..

c4   sum({<c4={1}>}c4)..

tresesco
MVP
MVP

Try this:

Pick(Match(TYPE,$(=Concat(DISTINCT chr(39)&TYPE&chr(39), ','))),

  $(=Concat(DISTINCT 'Sum({<'

  &TYPE&

  '={1}>}['

  &TYPE&'])' ,','))

  )

chhavi376
Creator II
Creator II
Author

I have already made a variable which is to be used as set analysis

If(GetSelectedCount([Type Indication])>=1,

'{<'&Type&'={1}' &Concat(DISTINCT SubField([Type Indication],':',1)& if( SubField([Type Indication],':',2)=' Require', '={1}','={0}'))&'>}'

)

Adding Type&'={1}' is giving internal error

chhavi376
Creator II
Creator II
Author

This variable has been used in the expression u suggested:

Pick(Match(Type,$(=Concat(DISTINCT chr(39)&Type&chr(39), ','))),

  $(=Concat(DISTINCT 'Sum($(test)['

  &Type&'])' ,','))

  )

tresesco
MVP
MVP

Hi Chhavi,

If you want me to help with your actual qv, try to share the same with sample data. That would help me help you.

chhavi376
Creator II
Creator II
Author

Give me 15 min.. I will update it..