3 Replies Latest reply: Dec 22, 2014 10:27 AM by Александр Закревский

# Count(if(aggr)) counts only the first value. Why?

I've got 2 tables:

```t1:
[
CID,TID,Tdate
1,1,25.12.2014
1,2,20.05.2014
2,3,14.03.2015
1,4,28.10.2015
];
t2:
[
CID,EID,Edate
1,9,18.05.2014
1,7,16.05.2014
1,1,21.05.2014
1,2,19.05.2014
2,3,20.05.2014
1,4,29.11.2015
1,5,26.05.2014
1,6,15.04.2014
1,8,17.06.2014
];
```

and a straight table chart with a dimension CID and expression

```Count(if(aggr(min(TDATE),CID)>EDATE, EID))
```

The count shows values = 1 for both CIDs, inspite that there are several (4) EIDs for CID=1 that suit the condition. I found out that the Count finds only the first suitable EDATE in the table, but for all others the condition is false. What's wrong?

• ###### Re: Count(if(aggr)) counts only the first value. Why?

Hi,

Try this

Count(If(Aggr(NODISTINCT Min(TDATE),CID)>Aggr(Only(EDATE),CID,EID),EID))

• ###### Re: Count(if(aggr)) counts only the first value. Why?

=SUM(IF(Date(Aggr(Only(EDATE),EID,CID)) <=Aggr(NODISTINCT Min(TDATE),CID),1,0))

• ###### Re: Count(if(aggr)) counts only the first value. Why?

Actually, in my case, adding nodistinct to aggr in initial expression solved the problem. So it became

`Count(if(aggr(nodistinct min(TDATE),CID)>EDATE, EID))`

But the real data model appears to be much more complicated and the trick doesn't work well. So I'll try to adapt it to my solution. If fail, I'll come back for more assistance. Anyway, thank you, guys!