Forum Discussion

paweldm's avatar
paweldm
Helper II
9 years ago
Solved

Last invoice amount

HI,   Problem: How can I  calculate last invoice amount?   Simplified Model:  Customer Table with the following column: CustomerID  (Thera are only unique customers' id)   Sales Table with th...
  • SqlJason's avatar
    9 years ago

    What you want is an application of what we call "Last Non Empty" order. There are 4 types of Last Non Empty patterns, and if you want to dive deep into it, I would recommend you to one of my old blogs -

    http://sqljason.com/2012/06/lastnonempty-in-tabular-mode-part-1.html

     

    If you just want the solution, my understanding is that you want the last non empty order for all customers on that date.

    Sales_LNE :=
    CALCULATE ( SUM ( Sales[Sales] ), LASTDATE ( Sales[Date] ) )

     This is the first pattern from my blog (and you can also use a filter() instead of the lastdate()). If the last date is different for every customer (which means, if you dont get orders for all customers on each date), you might want to use the second pattern with SUMX.