10 Replies Latest reply: Jun 29, 2017 5:05 AM by Stefan Wühl

# IF(SUM())

Hello,

I have a field called visitCount.  Using this field, I calculate sum of visit that client had ie  sum(visitCount).

I would like to create a flag, that would allow me to select client that had more that 6 visits.

I have been trying to  --         if(sum(visitCount) > 6, 'y', 'n') but it has not worked.

Can anyone suggest an alternative method of tackling this issue.

Thank you,

• ###### Re: IF(SUM())

Are you doing this in the script? Make sure you use Group by clause if you are doing this in the script

• ###### Re: IF(SUM())

not in the data load editor

• ###### Re: IF(SUM())

Then where?

• ###### Re: IF(SUM())

Each record under the visitCount has  a value of 1 for a visit.

I created a table with the following field

id| ClientName|  Start Year| Start Month| #ofVisits [which is  sum(visitCount)], Morethan6VisitFlag

1      AA               2017           2                  10                                                       y

2      AB               2017           3                   4                                                        n

3     AC               2017           3                    2                                                        n

Separately I would like to create a flag when there are more than 6 visits.

Hope this helps,

if there is another method to do it, then I would be glad to learn.

Thank you

• ###### Re: IF(SUM())

May be this

If(Sum(visitCount) > 6, 'y', 'n')

• ###### Re: IF(SUM())

I tried this before and it did not work.

Can if and sum be used together  ie  if(sum())

Has it worked in the past for you?

• ###### Re: IF(SUM())

Yes it has.... can you share a sample or images where it isn't working?

• ###### Re: IF(SUM())

Try creating a filter pane with a calculated dimension / field like

=Aggr( If(Sum(visitCount) >6, 'y','n') , id)

This will group your records by id field ( as I understood, id is a field that you used as dimension in your table chart, that identifies each row, maybe you can also use ClientName instead) and calculates the Sum(visitCount) per id. Just like a temporary table.

Result should be two values in your filter pane, 'y' and 'n'. Selecting one of the values should filter your id's.

Hope this helps,

Stefan

edit:

and if you need to ignore certain selections that limit the ids, you need to use set analysis in the Sum(), for example to ignore all selections:

=Aggr( If( Sum({1} visitCount) >6, 'y','n') , id)

• ###### Re: IF(SUM())

May be try this:

if(visitCount>6,'y','n')

• ###### Re: IF(SUM())

Hi Salamon Musayev, in this case if u mention that the fiel visitcount save number 1 for each visit i think the correct form for u solution would be this.

1. Do the load of Your table, for the fuield countvisit must be a count(), in order to count all the visits for each Clientname, for this the group by, and in the superior part of the table a precedent load giving it the codition for the flag.

TABLE_TEMP:

*,

if(VISITCOUNTER>6,'Y', 'N') AS FLAG;

id,

ClientName,

"  Start Year",

"Start Month",

COUNT(visitcount) as VISITCOUNTER

FROM [table_source]

GROUP BY id, ClientName, "  Start Year", "Start Month";

I could undertand this, if I am wrong please let me know.