Skip to main content
Woohoo! Qlik Community has won “Best in Class Community” in the 2024 Khoros Kudos awards!
Announcements
Nov. 20th, Qlik Insider - Lakehouses: Driving the Future of Data & AI - PICK A SESSION
cancel
Showing results for 
Search instead for 
Did you mean: 
jduluc12
Creator
Creator

Aggr () inside if

Hi,
I am writing this expression

if (Product.Amount > 0 and aggr(count(distinct Product.SalesDates),Product) > 0, Product.Name)

then it works

but when i do

if (Product.Amount > 0 and aggr(count(distinct Product.SalesDates),Product) = 0, Product.Name)


then it does not work.


The data is available for the second expression also.


why?

12 Replies
Chanty4u
MVP
MVP

try below

aggr((count(distinct Product.SalesDates) = 0),if (Product.Amount > 0),Product.Name)

Peter_Cammaert
Partner - Champion III
Partner - Champion III

Can you describe the context of this expression? If it's used in a straight table, please specify which dimensions are used.

jduluc12
Creator
Creator
Author

It has the same problem,

It works when i use >0 and does not work when i use =0

jduluc12
Creator
Creator
Author

It is in a pivot table.

The dimension used is Product.Name.

Peter_Cammaert
Partner - Champion III
Partner - Champion III

Why do you use aggr() when a Product selection is being made by the dimension anyway?

If PRoduct.Amount is connected to Product.Name is connected to Product in a 1:1 fashion, and each Product may have zero or more SalesDates, then what about this expression:

IF ((Product.Amount > 0) and (Count(DISTINCT Product.SalesDates) = 0), ...)

jduluc12
Creator
Creator
Author

I think count needs aggr() else it shows "error in the calculated dimension"

Peter_Cammaert
Partner - Champion III
Partner - Champion III

So you are actually using this expression in a Dimension? Not just the Product.Name as a dimension?

Please describe what it should produce as dimension values. Thanks.

jduluc12
Creator
Creator
Author

you are right.

this is dimension. the dimension value should be the product name which does not have any sales date associated with it.

Peter_Cammaert
Partner - Champion III
Partner - Champion III

And what is the actual expression? You're sure you can't reduce the set of available Product.Names to those without sales by using set analysis in your expression?