Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
VanDuongLS
Frequent Visitor

How to find oustanding invoices in sales report based on the ending balance of account receivable

Dear Sir/Madam, 

I have a problem that needs to be solved: How do I find overdue invoices in sales reports to calculate the overdue debt of each invoice?
I have 1 sales report table and 1 ending balance table as follows:

VanDuongLS_5-1701046611340.png

 

VanDuongLS_4-1701046583769.png

The ending balance of customer A or B is always the sum of invoices ordered from the newest date to the oldest date.

Can you please help me solve this problem? Thank you very much!

 

link of files: 

https://drive.google.com/drive/folders/1SXAchLesIHAxKmv2J0SlXW2okLkRaakR?usp=sharing

 

1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi @VanDuongLS ,

Adavanced editor:

let
    Source = #"Sales report",
    #"Sorted Rows" = Table.Sort(Source,{{"Invoice date", Order.Descending}}),
    #"Grouped Rows" = Table.Group(#"Sorted Rows", {"Customer Name"}, 
    {{"end balance", 
    each 
    let
    table1 = Table.SelectRows(_,each [Outstanding]="x"),
    listdate = table1[#"Invoice date"],
    maxdate = List.Max(listdate),
    mindate = List.Min(listdate),
    result = if maxdate = mindate then List.Sum(Table.SelectRows(_,each [#"Invoice date"]=mindate)[#"Invoice Amt"]) else List.Sum(Table.SelectRows(_,each [#"Invoice date"]>mindate and [#"Invoice date"]<=maxdate)[#"Invoice Amt"])
    in
    result
    }})
in
    #"Grouped Rows"

Output:

vcgaomsft_0-1701340195123.png

Best Regards,
Gao

Community Support Team

 

If there is any post helps, then please consider Accept it as the solution  to help the other members find it more quickly.
If I misunderstand your needs or you still have problems on it, please feel free to let us know. Thanks a lot!

How to get your questions answered quickly --  How to provide sample data in the Power BI Forum -- China Power BI User Group

View solution in original post

2 REPLIES 2
Anonymous
Not applicable

Hi @VanDuongLS ,

Adavanced editor:

let
    Source = #"Sales report",
    #"Sorted Rows" = Table.Sort(Source,{{"Invoice date", Order.Descending}}),
    #"Grouped Rows" = Table.Group(#"Sorted Rows", {"Customer Name"}, 
    {{"end balance", 
    each 
    let
    table1 = Table.SelectRows(_,each [Outstanding]="x"),
    listdate = table1[#"Invoice date"],
    maxdate = List.Max(listdate),
    mindate = List.Min(listdate),
    result = if maxdate = mindate then List.Sum(Table.SelectRows(_,each [#"Invoice date"]=mindate)[#"Invoice Amt"]) else List.Sum(Table.SelectRows(_,each [#"Invoice date"]>mindate and [#"Invoice date"]<=maxdate)[#"Invoice Amt"])
    in
    result
    }})
in
    #"Grouped Rows"

Output:

vcgaomsft_0-1701340195123.png

Best Regards,
Gao

Community Support Team

 

If there is any post helps, then please consider Accept it as the solution  to help the other members find it more quickly.
If I misunderstand your needs or you still have problems on it, please feel free to let us know. Thanks a lot!

How to get your questions answered quickly --  How to provide sample data in the Power BI Forum -- China Power BI User Group

VanDuongLS
Frequent Visitor

Can anyone help me, please...

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

December 2025 Power BI Update Carousel

Power BI Monthly Update - December 2025

Check out the December 2025 Power BI Holiday Recap!

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.