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

Score big with last-minute savings on the final tickets to FabCon Vienna. Secure your discount

Reply
magnifybi
Resolver I
Resolver I

Show quantity of last calendar week based on todays date always

Hi,

 

I have been trying to get this to work for ages but can't seem to incorporate today's date in my week calculation.

 

Essentially I want it to look at todays date dynamically, check what week number this day is in and bring me back the quantity for the week before that.

 

This is what I have;

 

Quantity Last Week =
CALCULATE([Quantity Total],
FILTER(ALL('vw_DateDim'),
vw_DateDim[WeekOfYear]=(vw_DateDim[WeekOfYear])-1))
 
Thanks for the help guys,
 
Jon
1 ACCEPTED SOLUTION

Basically you should use variables.  Meta code here:

 

Var thisweek = weeknumber(today())

Var amount = calculate(xxx,weeknumber[date]=thisweek-1)

Return amount

 

This will only work for week 2 and up in a year.  If you want a better solution covering multiple years you need to introduce a YearWeek column in your dates table.

 

Final Caveat: TODAY() uses UTC in the service - this can lead to unexpected results depending where you live.

View solution in original post

4 REPLIES 4
lbendlin
Super User
Super User

What should happen when today's date is Jan 1st?

Didn't even think of that, but would love it to brink back the last week of the previous year!

 

Basically you should use variables.  Meta code here:

 

Var thisweek = weeknumber(today())

Var amount = calculate(xxx,weeknumber[date]=thisweek-1)

Return amount

 

This will only work for week 2 and up in a year.  If you want a better solution covering multiple years you need to introduce a YearWeek column in your dates table.

 

Final Caveat: TODAY() uses UTC in the service - this can lead to unexpected results depending where you live.

Thanks so much, I think i have it, it seems to not respond to my date slicers which is good, until there is no data.

 

For instance, If I change the date slicers to full year 2020, or first 6 months it works, but if I change it to July for instance, the measure goes blank, any idea why? Is it because I'm filtering out the data for it to calculate?

 

Quantity Last Week =
Var thisweek = WEEKNUM(today())
Var amount = calculate(Transactions[Quantity Total],vw_DateDim[WeekOfYear]=thisweek-1)
Return amount
 
Any way to ignore the date slicers?

 

 

Helpful resources

Announcements
August Power BI Update Carousel

Power BI Monthly Update - August 2025

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

August 2025 community update carousel

Fabric Community Update - August 2025

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