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

Count Based on Table

I'm struggling to get my head around how I can count the number of Customers I have in arrears, per Portfolio, down to a single number.

For instance I have the following data set:

Portfolio Customer.code Customer.name Relationship W_InvAmount W_RecAmount Water Balance In Arrears? 
    9318.13-9043.1275.034
Jack3100015Diana HammondNon-Rent Ex/Trf Tenant57.33-57.330 
Jack3100020Mechelle YangNon-Rent Tenant691.9-691.90 
Jack3100040Brielle EnglandNon-Rent Tenant688.5-688.50 
Bob3100084Hu WigginsNon-Rent Tenant470.9-470.90 
Mary3100008Oliver TravisNon-Rent Tenant457.74-457.740 
Jane3100042.01Jada BestNon-Rent Ex/Trf Tenant167.72-167.720 
Peter3100030Minerva OconnorNon-Rent Tenant275.49-275.490 
Peter3100074Xerxes SkinnerNon-Rent Tenant510.06-410.06100.001
Fred3100007Adrian SerranoNon-Rent Tenant8.5-8.50 
Fred3100010Hu BriggsNon-Rent Tenant128.19-128.190 
Fred3100046Reed MonroeNon-Rent Tenant1868.55-1640228.551
Susan3100014Yasir SearsNon-Rent Tenant336.55-336.550 
Susan3100066Morgan GibbsNon-Rent Tenant443.7-443.701
Susan3100069Yuri TaylorNon-Rent Tenant425-4250 
Kurt3100042Brody BondNon-Rent Tenant756.5-710.0246.481
Kurt3100080Ivy PerezNon-Rent Tenant314.5-314.50 
Dave3100049Allistair DyerNon-Rent Tenant435.2-435.20 
Dave3100068Judith GarciaNon-Rent Tenant1281.8-1281.80 

 

W_InvAmount is worked out by the following:

=SUM(IF(ARInvoice.orderNumber='WATER' AND ARInvoice.postingDate<=$(vReportDate),ARInvoice.rwLCGross))

 

W_RecAmount is worked out by the following:

=SUM(IF(ARInvoice.orderNumber='WATER' AND InvoiceApplyDetail.appliedDate<=$(vReportDate),InvoiceApplyDetail.fcAmount))

 

And Water Balance is worked out by adding the 2 expressions together

[W_InvAmount]+[W_RecAmount]

 

This then allows me to workout if [Water Balance] > 0 then put a 1 in the "In Arrears?" column.

All works perfectly whilst its in a table, however I am in the process of trying to put together KPI sheets for each Portfolio name on a separate sheet and counting how many customers they have that are in arrears as a single number.

I have moved the W_InvAmount and W_RecAmount expression formulas to a Variable and used these Variables in the Expression with the Portfolio Name as the Dimension, however it is making making my calculation based on the whole data set of the portfolio, not individual customer.

I am guessing I need to use the AGGR function somehow to accomplish this, but I am at a loss as how to how to achieve this.

Any help would be much appreciated.

Labels (3)
1 Solution

Accepted Solutions
tresesco
MVP
MVP

Dimension : Portfolio

Exp: Sum(Aggr(If($(vCalc_WInvAmount)+$(vCalc_WRecAmount)>0.5,1,0),Relationship,Customer.code, Portfolio))

tresesco_0-1591777673289.png

 

View solution in original post

7 Replies
tresesco
MVP
MVP

You are right, aggr() is something you have to look for. Try like:

Sum(Aggr(Sum(If(......)), CustomerField))

lukegilligan
Contributor III
Contributor III
Author

Thanks for the reply @tresesco

So I have done the following:

 

COUNT(AGGR(SUM($(vCalc_WInvAmount)+$(vCalc_WRecAmount)),Customer.code))

 

This gives me the count per portfolio overall, but still not just at arrears level. 

Portfolio  COUNT(AGGR(SUM(9318.13+-9043.10),Customer.code)) 
 18
Jack3
Bib1
Mary1
Jane1
Peter2
Fred3
Susan3
Kurt2
Dave2

 

This is what I am wanting it to show:

Portfolio  In Arrears? 
 4
Jack0
Bob0
Mary0
Jane0
Peter1
Fred1
Susan1
Kurt1
Dave0

 

tresesco
MVP
MVP

It seems you have to include other dimensions as well in aggr() and put a condition checking >1 in it. Could you prepare a sample app and share so that we can have a look into it and play to help?

lukegilligan
Contributor III
Contributor III
Author

@tresesco I have pulled the data in to an inline table and re-created the app (there are very small discrepancies, but they won't affect the calculations).

I really appreciate you taking the time to have a look at this for me.

tresesco
MVP
MVP

Dimension : Portfolio

Exp: Sum(Aggr(If($(vCalc_WInvAmount)+$(vCalc_WRecAmount)>0.5,1,0),Relationship,Customer.code, Portfolio))

tresesco_0-1591777673289.png

 

lukegilligan
Contributor III
Contributor III
Author

@tresesco Mate you are a deadest legend!! This worked perfectly.

Just so I can understand, the code does the following:

If($(vCalc_WInvAmount)+$(vCalc_WRecAmount)>0.5,1,0),Customer.code

If the balance is greater than .5 its a 1 otherwise its 0 per Customer.code

Sum(Aggr(..., Portfolio))

 This then sums the number of "1's" per Portfolio.

What does the Relationship section do in the aggr code?

Thanks again!!

tresesco
MVP
MVP

I saw that dimension in your table being used, so included in your calculation as well - you would know the data granularity better, if that is not impacting you can remove it.