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

Get certified in Microsoft Fabric—for free! For a limited time, the Microsoft Fabric Community team will be offering free DP-600 exam vouchers. Prepare now

Reply
Anonymous
Not applicable

This week date measure

Hi ,

can we create a measure to return all the dates that belongs to this week ? and last year same week ? 

 

this week dates =
var todaydate = TODAY()
var startdate= CALCULATE(SUM(DimTimeCalendar[WeekPeriodStarting]),DimTimeCalendar[Date_Key]=todaydate)
var enddate= CALCULATE(SUM(DimTimeCalendar[WeekPeriodEnding]),DimTimeCalendar[Date_Key]=todaydate)
RETURN
DATESBETWEEN ( Dimtimecalendar[date_key], StartDate, EndDate )
 
Like this i am using right now and storing it in a calculated table . Is this the right way ? or we can use a better way to do this .
 
let me tell you my original problem .. so i need in a tabular format this week sales and last week sales . in a same table 
Arkaprava_0-1641807763654.png

kind of like this .. lw means last week . and i am giving the dax also 

GP$$ = SUM(FactSales[GpFexchangeRate])
 
GP Lw =
CALCULATE(
FactSales[GP$$],all(FactSales),
FactSales[Sale Date]=SELECTEDVALUE(FactSales[Sale Date])-7)
 
 
GP this week =
var datetoday=TODAY()
var thisweek=calculate(max(DimTimeCalendar[Fiscalweeknumber]),filter(all(DimTimeCalendar),DimTimeCalendar[Date_Key]=datetoday))
var thisyear=calculate(MAX(DimTimeCalendar[FiscalYear]),filter(all(DimTimeCalendar),DimTimeCalendar[Date_Key]=datetoday))
return
CALCULATE(
sum( FactSales[GpFexchangeRate]),
DimTimeCalendar[Fiscalweeknumber]=thisweek,DimTimeCalendar[Year]=thisyear
)
 
 
Is this the right way ? i am new to power bi . please help me to find a better solution 
1 ACCEPTED SOLUTION
v-stephen-msft
Community Support
Community Support

Hi @Anonymous ,

 

I think you want the matrix to show the values for this week and the previous week.

Here's my solution.

1.Create a calendar table.

Calendar = CALENDAR(MIN('Table'[Date]),MAX('Table'[Date]))

vstephenmsft_0-1642059282711.png

 

2.Create a measure, put it into visual level filters and set show items when the value is 1.

Measure = var _thisweek=WEEKNUM(TODAY(),2)
var _week=WEEKNUM(MAX('Calendar'[Date]),2)
return IF(_thisweek=_week||_thisweek-1=_week,1)

vstephenmsft_1-1642059336979.png

 

As shown above, the view shows the data for this week and the previous week.

 

Best Regards,

Stephen Tao

 

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

7 REPLIES 7
v-stephen-msft
Community Support
Community Support

Hi @Anonymous ,

 

I think you want the matrix to show the values for this week and the previous week.

Here's my solution.

1.Create a calendar table.

Calendar = CALENDAR(MIN('Table'[Date]),MAX('Table'[Date]))

vstephenmsft_0-1642059282711.png

 

2.Create a measure, put it into visual level filters and set show items when the value is 1.

Measure = var _thisweek=WEEKNUM(TODAY(),2)
var _week=WEEKNUM(MAX('Calendar'[Date]),2)
return IF(_thisweek=_week||_thisweek-1=_week,1)

vstephenmsft_1-1642059336979.png

 

As shown above, the view shows the data for this week and the previous week.

 

Best Regards,

Stephen Tao

 

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Hi Stephen, i am trying to create a filter that once i click on it it will show me "This Week" and "This Month."

 

This example got me pretty close but wondering if you could me.14.PNG

 

Thank you,

Pablo

Hi @PabloGiraldo 
Could you please clarify what these periods of time mean?
Does "today" refer to the day the user looks at the report?
Does the current week start on "today" and last -7 days?
Does the current month start on "today" and last -30 days?

Regards,
Rita Fainshtein | Microsoft MVP
https://www.linkedin.com/in/rita-fainshtein/
Blog : https://www.madeiradata.com/profile/ritaf/profile

"Today" referes to the day the user looks at report.

Current week will be Monday through Friday. So taking this week as an example, current week will be May 15th through May 19th.

Current Month will be May 1st through May 31st.

 

Thank you!

It is difficult to produce a slicer you are interested in because the periods are included in each other.
There is the option of a generic slicer
The relative date.
My recommendation is to simply use it:

Ritaf1983_0-1684205347605.png

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly

Regards,
Rita Fainshtein | Microsoft MVP
https://www.linkedin.com/in/rita-fainshtein/
Blog : https://www.madeiradata.com/profile/ritaf/profile

Got it.

Thank you for your help!

amitchandak
Super User
Super User

@Anonymous . Last year same weekday or same week

measure

week Year behind Sales = CALCULATE(SUM(Sales[Sales Amount]),dateadd('Date'[Date],-364,DAY))

 

OR new columns in date table 


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

 

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))
Last year Week= CALCULATE(sum('Table'[Qty]), FILTER(ALL('Date'),'Date'[Week Rank]=(max('Date'[Week Rank]) -52)))

or

 

Last year Week= CALCULATE(sum('Table'[Qty]), FILTER(ALL('Date'),'Date'[Week Rank]=(max('Date'[Week Rank]) -53)))

 


Last year same week  = CALCULATE(sum('Table'[Qty]), FILTER(ALL('Date'),'Date'[Year]=max('Date'[Year])-1 && 'Date'[Week] = Max('Date'[Week])))

 

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

Join us as experts from around the world come together to shape the future of data and AI!
At the Microsoft Analytics Community Conference, global leaders and influential voices are stepping up to share their knowledge and help you master the latest in Microsoft Fabric, Copilot, and Purview.
️ November 12th-14th, 2024
 Online Event
Register Here

Helpful resources

Announcements
September Hackathon Carousel

Microsoft Fabric & AI Learning Hackathon

Learn from experts, get hands-on experience, and win awesome prizes.

October NL Carousel

Fabric Community Update - October 2024

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

Top Kudoed Authors