Skip to main content
Announcements
Join us at Qlik Connect for 3 magical days of learning, networking,and inspiration! REGISTER TODAY and save!
cancel
Showing results for 
Search instead for 
Did you mean: 
laureadiaz
Contributor III
Contributor III

Set analysis with AGGR If statement

I am trying to limit selections in an expression that has AGGR. I want to have in a graph what the lack of selection is for comparison.

This one is working:

=
(
Sum
({$<
Inside_Sales=>}
(
IF((AGGR(Sales_Price_SP, Short_ID, Sales_Num, Inside_Sales)>0)
and (AGGR(Sales_Qty_SP, Short_ID, Sales_Num, Inside_Sales)>0),
(
Sales_Price_SP-Sales_Cost_SP)))))

This one is not ignoring the selection for comparison

=
(
Sum
({$<
Inside_Sales=>}
(
IF((AGGR(Sales_Price_SP, Short_ID, Sales_Num, Inside_Sales)>0)
and (AGGR(Sales_Qty_SP, Short_ID, Sales_Num, Inside_Sales)>0),
(
Sales_Price_SP-Sales_Cost_SP)))))

I have a feeling it has to do with the AGGR but not sure.


Thanks in advance for the help/

1 Solution

Accepted Solutions
sunny_talwar

For your sample attached... try this

=Sum({$<Inside_Sales=>} Aggr(If(Only({$<Inside_Sales=>}Sales_Price_SP) > 0 and Only({$<Inside_Sales=>} Sales_Qty_SP) > 0, Only({$<Inside_Sales=>} Sales_Price_SP - Sales_Cost_SP)), Short_ID, Sales_Num, Month, Year))


Capture.PNG

View solution in original post

22 Replies
trdandamudi
Master II
Master II

Can you be little specific and share a sample app please...

laureadiaz
Contributor III
Contributor III
Author

woops just realized I copied the same expression twice above. I cannot add an app sorry ( I also can't open any that people post her :,(

=
(
Sum(
(
IF((AGGR(Sales_Price_SP, Short_ID, Sales_Num, Inside_Sales)>0)
and (AGGR(Sales_Qty_SP, Short_ID, Sales_Num, Inside_Sales)>0),
(
Sales_Price_SP-Sales_Cost_SP)))))

does work.

but if I want to not let Inside_Sales be selectable via set analysis ({$<Inside_Sales=>} it does not work.

Maybe an ONLY statement will work but I am not sure, as the developer book and examples on here do not seem to match?!?

trdandamudi
Master II
Master II

Give a try with the below code:

=
(
Sum
({1<
Inside_Sales=>}
(
IF((AGGR(Sales_Price_SP, Short_ID, Sales_Num, Inside_Sales)>0)
and (AGGR(Sales_Qty_SP, Short_ID, Sales_Num, Inside_Sales)>0),
(
Sales_Price_SP-Sales_Cost_SP)))))

Note: I replaced $ with 1.

laureadiaz
Contributor III
Contributor III
Author

It is still not quite right, I am expecting the set analysis to stay the same as if Inside_Sales was not selected but keep other selections. with the 1 it is also not allowing other fields to not be selected as well.

Let's say if without Inside_Sales being selected the answer was 4.

Once I select something from inside sales, I would expect the one with the set analysis restriction to stay 4, and the other without the 1 or $ to reduce to 3 or 2, because I am drilling down.

trdandamudi
Master II
Master II

laureadiaz
Contributor III
Contributor III
Author

I did read this one, which is how I cam up with:

(Sum
({$<
Inside_Sales=>}
(
IF((AGGR(Sales_Price_SP, Short_ID, Sales_Num, Inside_Sales)>0)
and (AGGR(Sales_Qty_SP, Short_ID, Sales_Num, Inside_Sales)>0),
(
Sales_Price_SP-Sales_Cost_SP)))))

The sad thing is if I get rid of the IF statement it works as I would want, but I need the IF to clean up data...

vishsaggi
Champion III
Champion III

Can you share a sample file you are working on and your expected output you are trying to achieve?

trdandamudi
Master II
Master II

Give a try on the below code:

(Sum

  ({<Inside_Sales=>}
  (IF((AGGR({<Inside_Sales=>} Sales_Price_SP, Short_ID, Sales_Num, Inside_Sales)>0)

          and

          (AGGR({<Inside_Sales=>}Sales_Qty_SP, Short_ID, Sales_Num, Inside_Sales)>0),
    (
Sales_Price_SP-Sales_Cost_SP
)))))


laureadiaz
Contributor III
Contributor III
Author

When adding the set analysis after AGGR, the equation is no longer loading properly, the top reads Expression OK, but the color coding stops at the first AGGR, like it's not really loading.