Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 
Imarins
Contributor
Contributor

Sum if after agrregation with condition

Hi guys,

im looking for a solution for this problem.

Im tryng to sum if a result of a aggregation return equal to 1.. if its more than 1 its 0.

expression:

sum(
        aggr(

            if(sum({$<mes_ano={">=$(varDataInicioMes)<=$(vDataFimMes)"}, flag_cpf={'1'}, TOP=>}flag_cpf)=1,1,0)

        ,cpf_cnpj_ajustado))

 

after , I divide this value for the total of cpf in the base.

The problem its that sometimes, when should return as 1, come back as 0. I already  look multiples post here but im stil stuck.

I need do this on the kpi chart (when I can do multiples filters), not in load script.

thanks.

 

Labels (3)
4 Replies
MayilVahanan

Hi
Try like below

sum({$<mes_ano={">=$(varDataInicioMes)<=$(vDataFimMes)"}, flag_cpf={'1'}, TOP=>}
        aggr(

            if(sum({$<mes_ano={">=$(varDataInicioMes)<=$(vDataFimMes)"}, flag_cpf={'1'}, TOP=>}flag_cpf)=1,1,0)

        ,cpf_cnpj_ajustado))

Thanks & Regards, Mayil Vahanan R
Please close the thread by marking correct answer & give likes if you like the post.
Imarins
Contributor
Contributor
Author

It didn't work...

Imarins
Contributor
Contributor
Author

I don't know if there is another way to do this.

All I need is caculate de amount of cpf that has only one claim in the base over all cpf in the base (distinct), and it has to be between the dates that are variable. I dont't know if the problem its because the variable dates.

I didn't did this on script because I need filter and see multiples scenarios.

 

Gabbar
Specialist
Specialist

Try This:

Count(

        aggr(

            if(sum({$<mes_ano={">=$(varDataInicioMes)<=$(vDataFimMes)"}, flag_cpf={'1'}, TOP=>}flag_cpf)=1,1,null())

        ,cpf_cnpj_ajustado))