Qlik Community

Qlik Sense App Development

Discussion board where members can learn more about Qlik Sense App Development and Usage.

jag7777777
New Contributor III

Set analysis with variables

Hi,

I have a couple of variables, each having the same sort of structure - which is summing stuff together. e.g.

vMarketableWeight = (SUM[field A] + SUM[field B] + SUM[field C] etc....)

These work fine when called from within a visualization with $(vMarketableWeight).

I've hit a snag using these with set analysis. The syntax I want to use is:

SUM({$<

    MarketableOrOutsize = "",

    [Size Bucket] = ""

    >}

    $(vMarketableWeight)/($(vMarketableWeight) + $(vOutsizeWeight))* 100

    )

This bit: $(vMarketableWeight)/($(vMarketableWeight) + $(vOutsizeWeight))* 100 works fine on its own.

I'm guessing it's something to do with sums of sums - or evaluation precedence....but my knowledge is limited.

Any ideas please?

I don't want to change the structure of my variables as they're well used.

Cheers,

12 Replies

Re: Set analysis with variables

Have you got missing bracket, maybe try something like this :

SUM({$<

    MarketableOrOutsize = "",

    [Size Bucket] = ""

    >}

  ($(vMarketableWeight)/($(vMarketableWeight) + $(vOutsizeWeight))* 100

    )

Also when you do $(vMarketableWeight)/($(vMarketableWeight) you are dividing $(vMarketableWeight) by itself and that will always return one - maybe a typo.

Re: Set analysis with variables

The expression in your variable contains aggregations: SUM(....). You then put an aggregation function into another aggregation: SUM(SUM(...)). That's nonsense unless you specify over which dimensions the inner sums should be aggregated. You need to use the aggr function to do that: SUM( AGGR( SUM(....) , DimA, DimB, ..., DimX)). See this document for more information: QlikView Technical Brief - AGGR.docx


talk is cheap, supply exceeds demand
jag7777777
New Contributor III

Re: Set analysis with variables

There are no inner dimensions? Like I've mentioned, the calculation works fine on its own - and with any selections made on any sheets.

I get that it's the sum or sum that's the problem....but not sure why I need to use the AGGR function to fix?

jag7777777
New Contributor III

Re: Set analysis with variables

Hi Cheers for the reply,

The calc works fine on its own. It's only when there's set analysis it doesn't work...which is due to the sum or sum problem.

Brackets are OK (I've tested without the set analysis) - and the internal brackets means it doesn't divide by itself as it forces the addition first (the underlined bit) - it probably seems backward the way it's laid out, but it's necessary as the outsize and marketable weights are built up of many size bands...all of which are valid in their own right (so have to be sums when the user makes multiple record selections), but all off which only ever belong to one set - Marketable or Outsize.

I'm 99% sure it's the SUM at the beginning of the set analysis that's the problem....just don't know how to fix it.

$(vMarketableWeight)/($(vMarketableWeight) + $(vOutsizeWeight))* 100

Re: Set analysis with variables

Then you do something like sum( sum(100) ). Which makes no sense and is not correct as far as Qlikview is concerned. Which is why you get an error. Use the aggr function if you nest aggregation functions. Or don't and figure it out yourself Perhaps this is what you're after: $(vMarketableWeight)/($(vMarketableWeight) + $(vOutsizeWeight))* 100

Perhaps this helps: It’s all Aggregations


talk is cheap, supply exceeds demand
vinieme12
Esteemed Contributor II

Re: Set analysis with variables

I think your Expression should be as below,the entire thing

SUM({$<

    MarketableOrOutsize = "",

    [Size Bucket] = ""

    >}

    $(vMarketableWeight) )

/

(

SUM({$<

    MarketableOrOutsize = "",

    [Size Bucket] = ""

    >} $(vMarketableWeight) )

+

SUM({$<

    MarketableOrOutsize = "",

    [Size Bucket] = ""

    >} $(vOutsizeWeight) )

)

jag7777777
New Contributor III

Re: Set analysis with variables

OK - no worries. Thanks for your help anyway.

jag7777777
New Contributor III

Re: Set analysis with variables

Cheers Vineeth. I tried that one too - but no luck! :-(

I know it's the SUM or SUMS that's the problem as my variables already contain summing.....so am guessing that's why this doesn't work either.

Cheers,

John

vinieme12
Esteemed Contributor II

Re: Set analysis with variables

Can you post the exact expression you used? want to make sure we are not  missing curly brackets

SUM({$<

    MarketableOrOutsize = {'VALUE'},

    [Size Bucket] ={''}

    >}

    $(vMarketableWeight) )

/

(

SUM({$<

  MarketableOrOutsize = {'VALUE'},

    [Size Bucket] ={''}

    >}

    >} $(vMarketableWeight) )

+

SUM({$<

  MarketableOrOutsize = {'VALUE'},

    [Size Bucket] ={''}

    >}

    >} $(vOutsizeWeight) )

)