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

Announcements
Discover how organizations are unlocking new revenue streams: Watch here
cancel
Showing results for 
Search instead for 
Did you mean: 
felix18807
Contributor III
Contributor III

Using a the value of a field to determine which field is totalled in an expression

I know I'm going to have difficulty explaining this one - apologies

I have to run a series of reports where the value being added up is dependent on the report/dimension being selected.

So for a where

Report = A / Distributor = B / Site = C    the expression is Sum ([Spend X])

but where
Report = A / Distributor = B / Site = D    the expression is Sum ([Spend Y])

I have got as far as creating a table that holds the Spend fieldname for each Report / Distributor / Site so I have which field should be totalled held in a field. What I don't know is if you can use this dynamically in the expression.

Has anyone got any experience of this?

Many Thanks

1 Solution

Accepted Solutions
marcus_malinow
Partner - Specialist III
Partner - Specialist III

Hi Richard,

try this expression

SUM($(=CONCAT(DISTINCT R_Field, '+')))

View solution in original post

6 Replies
marcus_malinow
Partner - Specialist III
Partner - Specialist III

Hi Richard,

this doesn't sound like anything too tricky. You have a couple of options:

In your load script, add a couple of flags like this:

If(Site='C',1,0) as SpendXFlag,

If(Site='D',1,0) as SpendYFlag,

then your expressions is:

Sum([Spend X] * SpendXFlag) + Sum([Spend Y] * SpendYFlag)

Or...

You could use this expression:

Sum(if(Site='C',[Spend X],If(Site='D',[Spend Y],0)))

I'd favour the first option personally.

Marcus

felix18807
Contributor III
Contributor III
Author

I thought this might be what was needed.

Unfortunately there are a lot of variations in the Report / Distributor / Site so I was hoping to be able to use something like SUM($(ValueFieldName)) - which doesn't seem to work (there is a table that links by a Report+Distributor+Site key that has a field "ValueFieldName" which has the name of the field that I want to total).

marcus_malinow
Partner - Specialist III
Partner - Specialist III

Hi Richard,

do you have an example doc you could upload? I think there's probably a way to do this in a similar way to the way you suggest. Probably this would use the AGGR function to set up a list of sums for each ValueFieldName, then sum those.

Marcus

felix18807
Contributor III
Contributor III
Author

I've thrown this together. I hope it helps...

marcus_malinow
Partner - Specialist III
Partner - Specialist III

Hi Richard,

try this expression

SUM($(=CONCAT(DISTINCT R_Field, '+')))

felix18807
Contributor III
Contributor III
Author

That is genius! Exactly what I needed!

Many many thanks Marcus