Skip to main content
Announcements
Qlik Connect 2024! Seize endless possibilities! LEARN MORE
cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

Sum on last date within group and second condition

The simple phrase is "Total of Sales from records when the last action on a account resulted in a status of "complete"

I'm working in textboxes and I'd like to get a total based on two conditions,

     1) The record has the max(time) within a group (just that record, not the sum of the entire group)

     2) A field in that record equals some text

Record#AccountUpdate DateTimeStatusSales
11234561/1/14 1 pmAssigned1
21234561/2/14 2 pmComplete2
39876541/2/14 1 pmComplete4
49876541/2/14 2 pmComplete8
59876541/3/14 1 pmComplete16
64569871/2/14 1 pmComplete32
74569871/3/14 2 pmAssigned64

Here are two examples and my expected output

     1) No filters, Total for "Complete" is 18, "Assigned" is 64

           - Records 2, 5, and 7 are considered because they are the last time within their respective account. One text box will sum up Complete (2+16), the other Assigned (64)

     2) The only date selected is 1/2/14, Total for "Complete" is 42, "Assigned" is 0

          - The filter for date (1/2/14) removes all but 2, 3, 4, and 6; The filter for last account times within those leaves 2, 4 and 6. (Since I want only one record per account, I take the record with the max time [that falls within the date filter] in account 987654) One text box will sum up Complete (2+8+32), the other Assigned (0)

I've been trying all sort of things with FirstSelectedValue(), Aggr(), set expressions and some if() statements.

=Sum(

  Aggr(

    FirstSortedValue({$<

        [Status]={'Complete'}

      >}

      [Sales],

      -[Update DateTime]

    )

    ,[Account]

  )

)

The problem with this is filtering on status gives strange results.

2 Replies
MK_QSL
MVP
MVP

Can you please elaborate little more with another example or explain bit more on the example you have given how you want 20, 64 44 and 0 results...

Not applicable
Author

Added some explanation in blue text, also changed the table a little to have a record# and broader base.