Skip to main content
Woohoo! Qlik Community has won “Best in Class Community” in the 2024 Khoros Kudos awards!
Announcements
Join us at Qlik Connect for 3 magical days of learning, networking,and inspiration! REGISTER TODAY and save!
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.

1 Solution

Accepted Solutions
tresesco
MVP
MVP

For a total UI solution try like:

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

  $(=Concat(DISTINCT 'Sum([' &TYPE&'])' ,','))

  )

Capture.JPG

View solution in original post

21 Replies
kaushiknsolanki
Partner Ambassador/MVP
Partner Ambassador/MVP

Hi,

Instead of using any function why dont you crosstab the table which you have using Crosstable() function?

Regards,

Kaushik Solanki

Please remember to hit the 'Like' button and for helpful answers and resolutions, click on the 'Accept As Solution' button. Cheers!
chhavi376
Creator II
Creator II
Author

I need to take the values from the base table only .. as i have to maintain the associativity.. Taking values from cross table will not have that relationship

MK_QSL
MVP
MVP

This can easily be achieved using crosstable functionality.

T1:

Load * Inline

[

TYPE

C1

C2

C3

C4

];


T2:

CrossTable(TYPE,Value)

Load RowNo(),* Inline

[

C1, C2, C3, C4

1, 1, 0, 1

1, 0, 1, 1

];

Now use Straight Table/Pivot Table

Dimension TYPE

Expression

SUM(Value)

MK_QSL
MVP
MVP

Or something like this

T1:

Load * Inline

[

TYPE

C1

C2

C3

C4

];


T2:

CrossTable(TYPE,Value)

Load RowNo(),* Inline

[

C1, C2, C3, C4

1, 1, 0, 1

1, 0, 1, 1

];


Left Join (T1)

Load TYPE,SUM(Value) as TotalValue Resident T2 Group By TYPE;


Drop Table T2;


T2:

Load * Inline

[

C1, C2, C3, C4

1, 1, 0, 1

1, 0, 1, 1

];

chhavi376
Creator II
Creator II
Author

Hi Manish,

I tried this already ...

But i need to to maintain the associativity between these columns(c1,c2,c3,c4). as user will have an option to filter on these columns also. and he wants to view the sum according to the filters selected

MK_QSL
MVP
MVP

check my 2nd reply

chhavi376
Creator II
Creator II
Author

In this case the sum will not vary with the selections in c1/2/3/4

chhavi376
Creator II
Creator II
Author

Is there any way in which i can convert the returned value of fieldvalue() to the column name?

tresesco
MVP
MVP

For a total UI solution try like:

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

  $(=Concat(DISTINCT 'Sum([' &TYPE&'])' ,','))

  )

Capture.JPG