# New to Qlik Sense

Discussion board where members can get started with Qlik Sense.

Highlighted
Not applicable

## Set Analysis function in a KPI

Hi all,

I'm trying to understand why my expression doesn't work.

The expression is:

```count( {\$<[WeightValue] = {"=if(flag_01 = 1, 0.25, 0)+if(flag_02 = 1, 0.25, 0)+if(flag_07 = 1, 0.25, 0)"} >} ID_Client )

```

In my table Client there is a column [WeightValue] that has always the value "0.25".

In the same table, i have 3 flags (flag_01, flag_02 and flag_03) which can assume the value 0 or 1.

I need to compare the value of the column [WeightValue] with the sum of the flags (as you can see in the expression).

In this case, I need to check if there are some client that have [WeightValue] = 0.25.

The KPI show me always the value 0 (so I can think that there are no Client that satisfy the equation).

But if I create a Table as ID_Client as Dimension and a Misure trought the funcion

```if(flag_01 = 1, 0.25, 0)+if(flag_02 = 1, 0.25, 0)+if(flag_07 = 1, 0.25, 0)

```

I can see that there are some client that have 0.25 as a result of the function.

The KPI show me the correct value if I select one of ID_Client that satisfy the equation (when getSelectedCount(ID_Client) = 1 and the equation is satisfied).

Can someone help me, please to understand wich is the problem?

Tags (4)
16 Replies
Honored Contributor III

## Re: Set Analysis function in a KPI

Hi Giuseppe,

in Table You have implicit Aggr of Dim ID_CLIENT.

In KPI You need Aggr() function like

Sum(Aggr(Count(Expression),ID_CLIENT))

Regards,

Antonio

Honored Contributor II

## Re: Set Analysis function in a KPI

Hi,

count( {\$<[WeightValue] = {"=if(flag_01 = 1,0.25,if(flag_02 = 1,0.25,if(flag_07 = 1,0.25,0)))"} >} ID_Client )

Not applicable

## Re: Set Analysis function in a KPI

Ok, but it give me the same result.

After some tests, now the KPI works in a strange way.

If I select (from a filter) only the ID_Client that satisfy the equation, the KPI shows the exact value.

For example, if I select 5 ID_Client that has [WeightValue] = F(x), it shows 5.

But if I select 5 ID_Client that satisfy the equation, and only one ID_Client that doesn't satisfy the equation, the KPI shows me 0. It think was correct if it shows 5, not 0.

Some ideas?

Not applicable

## Re: Set Analysis function in a KPI

###### Hi - devarasu07‌ - but I need to sum the value of the flags (flag1+flag2+flag3).

Honored Contributor III

## Re: Set Analysis function in a KPI

Set Analysis is evaluated once per object..

I think You need If() instead of Set Analysis in Your expression.

Honored Contributor II

## Re: Set Analysis function in a KPI

Hi,

Can you share your mock app and expected output. Tks

Not applicable

## Re: Set Analysis function in a KPI

Sorry, but I can't share the app.. there are data that i can't show.

Esteemed Contributor III

## Re: Set Analysis function in a KPI

Try if this helps:

count( {\$<[WeightValue] = {"\$(=if(flag_01 = 1, 0.25, 0)+if(flag_02 = 1, 0.25, 0)+if(flag_07 = 1, 0.25, 0))"} >} ID_Client )

New Contributor II

## Re: Set Analysis function in a KPI

I'm not sure I understand the problem, but it sounds like you just need a count of clientIDs where only 1 of the 3 flags is set to 1. I'm assuming that based on your if statement:

If that's the case the easiest what to accomplish this is to just create a new field in the script.

Here's what it would look like in the script:

flag_01 + flag_02 + flag_07 as CountWeightFlag

Then your set analysis would look like this:

Count({<CountWeightFlag={1}>}ID_Client )

If you don't have access to the script you can accomplish like this:

count({<flag_01={1}, flag_02={0}, flag_07={0}>}ID_Client ) + count({<flag_01={0}, flag_02={1}, flag_07={0}>}ID_Client )  + count({<flag_01={0}, flag_02={0}, flag_07={1}>}ID_Client )