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

Power BI is turning 10! Let’s celebrate together with dataviz contests, interactive sessions, and giveaways. Register now.

Reply
vickikrebs
Frequent Visitor

Sum if date is within last 7 calendar days of month

Hi,

 

I need to calculate the sum of the # of invoices, but only if the Date is in the last 7 calendar days of each month. I will have YTD data, updated daily.

# invoicesDate
76/27/2023
46/28/2023
26/29/2023
17/21/2023
27/22/2023
47/27/2023
57/28/2023
27/29/2023
37/31/2023

 

I thought about trying to create a column with "true" if it is in the last 7 days, and "false" if not. But I don't know how to write that. Anyone have ideas?

1 ACCEPTED SOLUTION

How about...

7dayEOMSum =
var selectedDate=selectedvalue(invoicesDate)
Calculate(sum(NumberOfInvoices), datediff(selectedDate, EOM(selectedDate,0),DAY)<=7)

 

If this post was helpful, please kudos or accept the answer as a solution.
~ Anthony Genovese
Need more PBI help? PM me for affordable, dedicated training or consultant recomendations!

View solution in original post

4 REPLIES 4
AnthonyGenovese
Resolver III
Resolver III

I would try something like this

 

7daySum = Calculate(sum(NumberOfInvoices), datediff(invoicesDate,today(),DAY)<=7)

 

If this post was helpful, please kudos or accept the answer as a solution.
~ Anthony Genovese
Need more PBI help? PM me for affordable, dedicated training or consultant recomendations!

I think..this one gives me past 7 days, instead of the last 7 days of the calendar month. Is it possible to get the last 7 days of the calendar month?

How about...

7dayEOMSum =
var selectedDate=selectedvalue(invoicesDate)
Calculate(sum(NumberOfInvoices), datediff(selectedDate, EOM(selectedDate,0),DAY)<=7)

 

If this post was helpful, please kudos or accept the answer as a solution.
~ Anthony Genovese
Need more PBI help? PM me for affordable, dedicated training or consultant recomendations!

Ooooh - that made me think. I got it to work with: 

 

Last week =
VAR EOM = EOMONTH('Num Invoices'[Date], 0)
Var DateDiff = DATEDIFF('Num Invoices'[Date], EOM, Day)
RETURN IF(DateDiff >= 0 && DateDiff < 7, "True", "False")
 
Thank you!!!

Helpful resources

Announcements
Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

Check out the June 2025 Power BI update to learn about new features.

June 2025 community update carousel

Fabric Community Update - June 2025

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