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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
Torbenan
Helper I
Helper I

Filtering based on date

Hi
i trying to calculate the amount that has been invoice during the last year. Since the table
Sales'[TotalInvoiceAmount] isn't update daily, I need to find the latest invoice date and
substrat 365 days. This is my formular:
Last12Month invoiced = CALCULATE(
    SUM('Sales'[TotalInvoiceAmount]);
FILTER(Sales; Sales[InvoiceDate].[Date] > LASTDATE(Sales[InvoiceDate].[Date]) - 365
))
 
No filtering is taking place, so what am I doing wrong. If I replace
"LASTDATE(Sales[InvoiceDate].[Date]) - 365" with "today() - 365", filtering works perfect.

1 ACCEPTED SOLUTION
calerof
Impactful Individual
Impactful Individual

Hi @Torbenan ,

 

Try using a variable like below:

Last12Month invoiced = VAR LastInvDate = LASTDATE( Sales[Date] )
                       RETURN
                       CALCULATE(
                             SUM(Sales[Sales]),
                             Sales[Date] > LastInvDate - 365
                       )

Hope it helps.

Cheers,

Fernando

 

View solution in original post

3 REPLIES 3
Anonymous
Not applicable

Hi @Torbenan ,

 

Are you using your measure in a visual that is using the InvoiceDate column? LASTDATE() will evaluate the last date based upon the current context whereas TODAY() does not take the context into account of course..

 

You could try calculating the LASTDATE in a variable beforehand using an ALL statement to remove any context filters from your date column?

 

Best,
Kris
calerof
Impactful Individual
Impactful Individual

Hi @Torbenan ,

 

Try using a variable like below:

Last12Month invoiced = VAR LastInvDate = LASTDATE( Sales[Date] )
                       RETURN
                       CALCULATE(
                             SUM(Sales[Sales]),
                             Sales[Date] > LastInvDate - 365
                       )

Hope it helps.

Cheers,

Fernando

 

This did the trick

Last12Monthinvoiced = VAR LastInvDate = LASTDATE( Sales[InvoiceDate] )
RETURN
CALCULATE(
SUM(Sales[TotalInvoiceAmount]);
Sales[InvoiceDate]> LastInvDate - 365
)

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.