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: 
Not applicable

Expression needed to calculate an amount.

Hello, everyone.

I have a table such as this.

Client #Invoice # Invoice Total ($)Invoice Amount Paid ($)
11010040
11010050
111200100
11120030
112300150
213900250
213900220
214800460

And in QV, I have a Chart such as this, where I want to calculate the total pending amount:

ClientTotal Pending Amount
1?
2?

That is, I want to take each Invoice Total for different Invoices and subtract Invoice Amount Paid.

For instance, for client 1, it would be: Total Pending Amount = 100 (because of invoice 10) + 200 (because of invoice 11) + 300 (because of invoice 12) - 40 - 50 - 100 - 30 - 150 (because of what has been paid for every invoice) = 230.

Could anyone help me please to achieve a expression for Total Pending Amount?

Thanks for reading.

8 Replies
alexandros17
Partner - Champion III
Partner - Champion III

Here it is:

Tab1:
Load * Inline [
Client #, Invoice #, Invoice Total ($), Invoice Amount Paid ($)
1, 10, 100, 40
1, 10, 100, 50
1, 11, 200, 100
1, 11, 200, 30
1, 12, 300, 150
2, 13, 900, 250
2, 13, 900, 220
2, 14, 800, 460
]
;

Tab2:
NoConcatenate
LOAD [Client #], Sum([Invoice Total ($)] - [Invoice Amount Paid ($)]) as InvPending Resident Tab1 Group By [Client #];
DROP Table Tab1;

Let me know

Not applicable
Author

Pending  amt.JPG

Not applicable
Author

Alessandro, thanks for your answer.

Unfortunately, it's not what I'm looking for.

First, because I actually want a set analysis expression to do so, but more importantly, because you are repeating the invoice total for every invoice.

For instance, for invoice 10, my total is 100 - 40 - 50 = 10, and not 100 + 100 - 40 - 50. The invoice total for invoice 10 is 100, and not 200.

Thanks anyway for your answer.

Not applicable
Author

Hi Sandeep.trs -

As I told Alessandro, the main problem here is that I have several rows for the same invoice. In your attached example (which I appreciate) no invoices are repeated, so the sum is pretty straightforward.

If you can, look at my example, which has a valid scenario (with repeated invoices). As I told Alessandro:

"For instance, for invoice 10, my total is 100 - 40 - 50 = 10, and not 100 + 100 - 40 - 50. The invoice total for invoice 10 is 100, and not 200."


Thanks!

Not applicable
Author

Use this expression then

Sum(Aggr(sum(DISTINCT [Invoice Total ($)]),[Client #],[Invoice #]))-Sum(aggr(Sum([Invoice Amount Paid ($)]),[Invoice #],[Client #]))Pending  amt.JPG

maxgro
MVP
MVP

sum(aggr(sum(DISTINCT [Invoice Total ($)]), [Client #], [Invoice #])) - sum([Invoice Amount Paid ($)])

Not applicable
Author

Hi,

Image.png

Digvijay_Singh

Same results by - Sum(DISTINCT [Invoice Total($)])-Sum([Invoice Amount Paid($)]) and Client# as the Dimension in Straight table chart