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

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.

Reply
andreas789
Frequent Visitor

Power BI Report Builder: DAX query to retrieve last week (Sunday - Saturday)

Hello, I need a DAX query, to query a power bi dataset for values in the last week and is equivalent to the following one:

 

  VAR __DS0FilterTable = 
    FILTER(
      KEEPFILTERS(VALUES('salesty'[TRANS_DATE])),
      AND(
        'salesty'[TRANS_DATE] >= DATE(2022, 1, 2),
        'salesty'[TRANS_DATE] < DATE(2022, 1, 9)
      )
    )

 

Basically, I think I need a DAX formula to get last week's values between Saturday and Saturday.

1 ACCEPTED SOLUTION
andreas789
Frequent Visitor

Thanks everybody for your suggestions.

Since the dataset was getting updated every monday, I was able to find a solution by using MAX function and subtracting the days.

View solution in original post

3 REPLIES 3
andreas789
Frequent Visitor

Thanks everybody for your suggestions.

Since the dataset was getting updated every monday, I was able to find a solution by using MAX function and subtracting the days.

ValtteriN
Super User
Super User

Hi,

You can use Weeknum to get this result. So something like this:

LastWeekT =
var weeknumLW = WEEKNUM(TODAY())-1
VAR __DS0FilterTable =
FILTER(
'LastWeek',
WEEKNUM('LastWeek'[Date])=weeknumLW
)
 
return
 
__DS0FilterTable


The default setting for WEEKNUM starts from Sunday so with this you should get last week with this dax. 

End result (visualized):
ValtteriN_0-1641809154625.png

 

Now you can just refer to this var tables columns e.g. in SUMX and you cant get the results you want. I hope this helps and if it does consider accepting this as a solution and giving the post a thumbs up!

 




Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




amitchandak
Super User
Super User

@andreas789 , You need these new columns in date tbale

 

new columns
Week Start date = 'Date'[Date]+-1*WEEKDAY('Date'[Date],1)+1
Week End date = 'Date'[Date]+ 7-1*WEEKDAY('Date'[Date],1)
Week Rank = RANKX(all('Date'),'Date'[Week Start date],,ASC,Dense)
OR
Week Rank = RANKX(all('Date'),'Date'[Year Week],,ASC,Dense) //YYYYWW format

 

then  measures
This Week = CALCULATE(sum('Table'[Qty]), FILTER(ALL('Date'),'Date'[Week Rank]=max('Date'[Week Rank])))
Last Week = CALCULATE(sum('Table'[Qty]), FILTER(ALL('Date'),'Date'[Week Rank]=max('Date'[Week Rank])-1))

 

Power BI — Week on Week and WTD
https://medium.com/@amitchandak.1978/power-bi-wtd-questions-time-intelligence-4-5-98c30fab69d3
https://community.powerbi.com/t5/Community-Blog/Week-Is-Not-So-Weak-WTD-Last-WTD-and-This-Week-vs-La...
https://www.youtube.com/watch?v=pnAesWxYgJ8

 

 

Hope the same work in report builder

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

Helpful resources

Announcements
July 2025 community update carousel

Fabric Community Update - July 2025

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

July PBI25 Carousel

Power BI Monthly Update - July 2025

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