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
Uzi2019
Super User
Super User

Last Week of selected Date range

Hi Expert,
I have one Date Range Slicer and As per the range selection it will calculate the Sale of the entire week data of that selected range.

For Example,

If User Selects End Range 4th, Aug 2022 so it will return Sales value of 1-4 Aug. 

Week should be considered as Monday to Sunday.

 

Please help me to calculate this using DAX.

 

Don't forget to give thumbs up and accept this as a solution if it helped you!!!
1 ACCEPTED SOLUTION
Tahreem24
Super User
Super User

Hi @Uzi2019 ,Try this:

Create Week No Column:

Week No = WEEKNUM('TableName'[DateColumn],2)


Then create another column for Week Ranking:

Week Rank = RANKX(ALL('TableName'),'TableName'[Week No],,ASC)

 

Then last step is to create a measure like below:


Current Week =
VAR latestWeek = CALCULATE(MAX('TableName'[Week Rank]),ALLSELECTED('TableName'))
VAR Result_ = CALCULATE(AVERAGE('TableName'[Sales]),FILTER('TableName','TableName'[Week Rank]=latestWeek))
RETURN Result_

 

Don't forget to give thumbs up and accept this as a solution if it helped you!!!

Please take a quick glance at newly created dashboards : Restaurant Management Dashboard , HR Analytics Report , Hotel Management Report, Sales Analysis Report , Fortune 500 Companies Analysis , Revenue Tracking Dashboard

View solution in original post

4 REPLIES 4
Tahreem24
Super User
Super User

Hi @Uzi2019 ,Try this:

Create Week No Column:

Week No = WEEKNUM('TableName'[DateColumn],2)


Then create another column for Week Ranking:

Week Rank = RANKX(ALL('TableName'),'TableName'[Week No],,ASC)

 

Then last step is to create a measure like below:


Current Week =
VAR latestWeek = CALCULATE(MAX('TableName'[Week Rank]),ALLSELECTED('TableName'))
VAR Result_ = CALCULATE(AVERAGE('TableName'[Sales]),FILTER('TableName','TableName'[Week Rank]=latestWeek))
RETURN Result_

 

Don't forget to give thumbs up and accept this as a solution if it helped you!!!

Please take a quick glance at newly created dashboards : Restaurant Management Dashboard , HR Analytics Report , Hotel Management Report, Sales Analysis Report , Fortune 500 Companies Analysis , Revenue Tracking Dashboard

Hi @Tahreem24 ,
Thanks alot. Your solution works for me.

Don't forget to give thumbs up and accept this as a solution if it helped you!!!
amitchandak
Super User
Super User

@Uzi2019 , Create a date table with following columns

 

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

weekday =  weekday([date],2)

 

Then measures like

WTD = CALCULATE(sum('Table'[Qty]), FILTER(ALL('Date'),'Date'[Week Rank]=max('Date'[Week Rank]) && 'Date'[WeekDay]<=max('Date'[WeekDay])-1))

 

LWTD = CALCULATE(sum('Table'[Qty]), FILTER(ALL('Date'),'Date'[Week Rank]=max('Date'[Week Rank])-1 && 'Date'[WeekDay]<=max('Date'[WeekDay])-1 ))

 

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

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

Hi @amitchandak 
I tried your solution it did not work.Do yu have any other way of doing it?

Don't forget to give thumbs up and accept this as a solution if it helped you!!!

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.