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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
Anonymous
Not applicable

Select Week Range from dropdown and Update YTD Figures to that week ending date

I have a dropdown to select a weekly range, the information updates on the visual for WTD (because I have edited the format to edit interactions for only the WTD visuals)

The YTD visuals are not touched by the weekly range selection, these numbers reflect the figures as of the last week range loaded in the data.

Example, I have year 2020, loaded 40 weeks, I can see the view of each week by selecting from the drop down week 30 or week 38, The YTD will show results as of week 40, because it's the last week range in the data.

 

How Do I insert a formula that shows results YTD as of the weekly range selected in the dropdown?

 

the formula for the weekly range is as follows:

 

Weekly range =
var startdateperweek=CALCULATE(MIN('Views '[Day]),FILTER('Views ','Views '[Day].[Year]=EARLIER('Views '[Day].[Year])&&'Views '[WeekNum]=EARLIER('Views '[WeekNum])))
var enddateperweek= CALCULATE(MAX('Views '[Day]),FILTER('Views ','Views '[Day].[Year]=EARLIER('Views '[Day].[Year])&&'Views '[WeekNum]=EARLIER('Views '[WeekNum])))
return
FORMAT(startdateperweek,"mm/d/yyyy")&" - " &FORMAT(enddateperweek,"mm/d/yyyy")

 

 

1 ACCEPTED SOLUTION
v-kelly-msft
Community Support
Community Support

Hi  @Anonymous ,

 

First create a dim week table as below:

 

Week table = VALUES('Views'[_Weeknum])

 

Then create a measure as below:

 

Weekly range = 
var startdateperweek=CALCULATE(MIN('Views'[Day]),FILTER(Views,YEAR('Views'[Day])=YEAR(MAX('Views'[Day]))&&'Views'[_Weeknum]=SELECTEDVALUE('Week table'[_Weeknum])))
var enddateperweek= CALCULATE(MAX('Views'[Day]),FILTER(Views,YEAR('Views'[Day])=YEAR(MAX('Views'[Day]))&&'Views'[_Weeknum]=SELECTEDVALUE('Week table'[_Weeknum])))
Return
FORMAT(startdateperweek,"mm/d/yyyy")&" - " &FORMAT(enddateperweek,"mm/d/yyyy")

 

And you will see:

 
 
 

v-kelly-msft_3-1610435971373.png

 

If you want all rows to show the weekly range,you could use below dax expression:

 

 

Weekly range = 
var startdateperweek=CALCULATE(MIN('Views'[Day]),FILTER(ALL(Views),YEAR('Views'[Day])=YEAR(MAX('Views'[Day]))&&'Views'[_Weeknum]=SELECTEDVALUE('Week table'[_Weeknum])))
var enddateperweek= CALCULATE(MAX('Views'[Day]),FILTER(ALL(Views),YEAR('Views'[Day])=YEAR(MAX('Views'[Day]))&&'Views'[_Weeknum]=SELECTEDVALUE('Week table'[_Weeknum])))
Return
FORMAT(startdateperweek,"mm/d/yyyy")&" - " &FORMAT(enddateperweek,"mm/d/yyyy")

 

 

For the related .pbix file,pls see attached.

 

Best Regards,
Kelly

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

View solution in original post

2 REPLIES 2
v-kelly-msft
Community Support
Community Support

Hi  @Anonymous ,

 

First create a dim week table as below:

 

Week table = VALUES('Views'[_Weeknum])

 

Then create a measure as below:

 

Weekly range = 
var startdateperweek=CALCULATE(MIN('Views'[Day]),FILTER(Views,YEAR('Views'[Day])=YEAR(MAX('Views'[Day]))&&'Views'[_Weeknum]=SELECTEDVALUE('Week table'[_Weeknum])))
var enddateperweek= CALCULATE(MAX('Views'[Day]),FILTER(Views,YEAR('Views'[Day])=YEAR(MAX('Views'[Day]))&&'Views'[_Weeknum]=SELECTEDVALUE('Week table'[_Weeknum])))
Return
FORMAT(startdateperweek,"mm/d/yyyy")&" - " &FORMAT(enddateperweek,"mm/d/yyyy")

 

And you will see:

 
 
 

v-kelly-msft_3-1610435971373.png

 

If you want all rows to show the weekly range,you could use below dax expression:

 

 

Weekly range = 
var startdateperweek=CALCULATE(MIN('Views'[Day]),FILTER(ALL(Views),YEAR('Views'[Day])=YEAR(MAX('Views'[Day]))&&'Views'[_Weeknum]=SELECTEDVALUE('Week table'[_Weeknum])))
var enddateperweek= CALCULATE(MAX('Views'[Day]),FILTER(ALL(Views),YEAR('Views'[Day])=YEAR(MAX('Views'[Day]))&&'Views'[_Weeknum]=SELECTEDVALUE('Week table'[_Weeknum])))
Return
FORMAT(startdateperweek,"mm/d/yyyy")&" - " &FORMAT(enddateperweek,"mm/d/yyyy")

 

 

For the related .pbix file,pls see attached.

 

Best Regards,
Kelly

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

amitchandak
Super User
Super User

@Anonymous , Make sure , you have week and year in new table

 

 

Try meaures like

YTD Week = CALCULATE(sum('order'[Qty]), FILTER(ALL('Date'),'Date'[Week Number]<=max('Date'[Week Number]) && 'Date'[Week Year]= max('Date'[Week Year])))


LYD Week = CALCULATE(sum('order'[Qty]), FILTER(ALL('Date'),'Date'[Week Number]=max('Date'[Week Number]) && 'Date'[Week Year]= max('Date'[Week Year])-1 ))

 

YTD Week = CALCULATE(sum('order'[Qty]), FILTER(ALL('Date'),'Date'[Week]<=max('Date'[Week]) && 'Date'[Year]= max('Date'[Year])))


LYD Week = CALCULATE(sum('order'[Qty]), FILTER(ALL('Date'),'Date'[Week ]=max('Date'[Week]) && 'Date'[Year]= max('Date'[Year])-1 ))

 

few columns which you can have , some are based on date

 

Week Start date = 'Date'[Date]+-1*WEEKDAY('Date'[Date],2)+1
Week End date = 'Date'[Date]+ 7-1*WEEKDAY('Date'[Date],2)
Week Number = WEEKNUM([Date],2)

 

Week Year = minx(filter('Date',[Year] =earlier([Year])),[Week Start date]) // based on start or end date of week

 

You can refer-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-Last-Week/ba-p/1051123
https://www.youtube.com/watch?v=pnAesWxYgJ8

 

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

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