Reputation: 315
I've a table 'invoice'
of amount with different Dates, i want to sum the amount for the max date.
For example if the max date is 25/03/2022, i'll sum only the rows of this date.
last_month_amount = calculate(SUM(invoice[amount]),FILTER(invoice, invoice[date] = LASTDATE('invoice'[date])))
but it calculate all the amounts without any filter.
in sql i want this:
select sum(invoice.amount)
from invoice
where invoice.date = (select max(date) from invoice)
but i got this
select sum(invoice.amount)
from invoice
Upvotes: 2
Views: 8235
Reputation: 8148
There are two errors in your formula:
To solve the problem, simply store the last date in a variable:
last_month_amount =
VAR Latest_Date = MAX ( 'invoice'[date] )
RETURN
CALCULATE ( SUM ( invoice[amount] ), 'invoice'[date] = Latest_Date )
Upvotes: 6