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

Calling all Data Engineers! Fabric Data Engineer (Exam DP-700) live sessions are back! Starting October 16th. Sign up.

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
FabCon Global Hackathon Carousel

FabCon Global Hackathon

Join the Fabric FabCon Global Hackathon—running virtually through Nov 3. Open to all skill levels. $10,000 in prizes!

September Power BI Update Carousel

Power BI Monthly Update - September 2025

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

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.