Skip to content
Advertisement

Max and Avg debt days over a period of time

I have invoices pending payment, every invoice has two dates, first when the invoice is required to pay and the other when the invoice is paid. I want to know in a period of time the max debt and the avg debt

This is the table

I would like to know the max debt amount in february and the avg debt

Advertisement

Answer

You can unpivot with cross apply, and use a window sum to compute the “running” debt at each given point in time. The rest is just filtering and aggregation:

User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement