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: 
ziabobaz
Creator III
Creator III

aggr (i think) function question

Hi,

I have the following data.

I want to SUM (AMOUNT) only those IDs, which are CONFIRMED and have CREATED status in the given period.

Trying the formula formula (it dosn't solve the problem):

SUM( {<status={'confirmed'}>}  AGGR ( SUM ( {<status={'created'}>} ) AMOUNT), ID ) )

The result should return 100 which is Confirmed amount for Order 500, because it has also Created status in the same period.

IDSTATUSAMOUNT
500created100
500confirmed100
700confirmed200

Thank you!

1 Solution

Accepted Solutions
sunny_talwar

Ignore the above two expressions... try this...

=Sum({<ID = P({<STATUS = {'confirmed'}>})*P({<STATUS = {'created'}>}), STATUS = {'confirmed'}>} AMOUNT)


Capture.PNG

View solution in original post

7 Replies
sunny_talwar

May be this

Sum({<ID = P({<status={'confirmed', 'created'}>})>} AMOUNT)

sunny_talwar

Actually this

Sum({<ID = P({<status = {'confirmed', 'created'}>}), status = {'confirmed'}>} AMOUNT)

sunny_talwar

Ignore the above two expressions... try this...

=Sum({<ID = P({<STATUS = {'confirmed'}>})*P({<STATUS = {'created'}>}), STATUS = {'confirmed'}>} AMOUNT)


Capture.PNG

swuehl
MVP
MVP

What does your original expression return?

Using Sunny's data model, it does also return 100.

Sunny's expressions should work though (and depending on your data model, you may not even need the last STATUS = {'confirmed'} modifier, i.e. if your AMOUNT is not given per STATUS record, but once per ID).

ziabobaz
Creator III
Creator III
Author

great, it works!

ziabobaz
Creator III
Creator III
Author

Stefan, my previous expression with AGGR returned nothing, because it was already aggregated by status Created (i.e. confirmed status was excluded)

The last Status=Confirmed should stay, otherwise it will sumup both Confirmed and Created. I only need the former.

swuehl
MVP
MVP

Using Sunny's QVW and correcting a small typo in your expression (removing a closing parenthesis):

ID =SUM( {<STATUS={'confirmed'}>} AGGR ( SUM ( {<STATUS={'created'}>} AMOUNT), ID ) )
100
500100

edit: I don't want to say that this expression is better than Sunny's. Just to understand why your original is not working.