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

Be one of the first to start using Fabric Databases. View on-demand sessions with database experts and the Microsoft product team to learn just how easy it is to get started. Watch now

Reply
StephenK
Resolver I
Resolver I

Weeks in Current Year Compared to Weeks in Previous Year

Hello all,

 

I'm attempting to build an analysis that compares the number of patient encounters by week for a set period this year (ie. last six calendar weeks) compared to the number of patient encounters by week for the same period last year.

 

I have not found a good solution as of yet. My data model consists of a Date Dim that includes calculated columns for Week Number in Year as well as a concatenated WeekNumber and Year column. My date dim is connected by a one to many relationship on the Date column to my fact table which also includes a date column.

 

I've tried creating a custom date hierarchy consisting of Year>Month>WeekNumber>Date. 

I then visualize this with a bar chart with the hierarchy on the axis and 2 measures in the values.

 

Measure 1 is a sum of all patient encounters: COUNT([encounterid]) 

Measure 2 is supposed to be the concurrent weeks for the previous year. I had attempted to do this by 

CALCULATE(COUNT([encounterid]),SAMEPERIODLASTYEAR('Date Dim',[Date]).

 

The report has a relative date slicer based on the date field in date dim.

 

My goal was to be able to analyze the prior year weeks compared to any year selected, hence the reason Measure 1 has no calculate/filter.

 

On the surface everything appears to work (the numbers after the month name are actually week numbers, not days), but the numbers start to go wonky depending on the period you're looking at. Example last six calendar weeks looks okay, but last eight calendar weeks starts to look weird...

screen1.JPGscreen2.JPG

 

Additionally, when i go into my dataview and do some spot checks on my weeks, i have dates disappearing and not showing up in that week for unapparent reasons--typically just one or two days here or there.

 

I've scoured the forums here for a solution and haven't found something that works. 

 

I feel like I'm missing an obvious solution with this, but I've been beating my head against the wall on this for too long now.

 

Any help would be greatly appreciated!

 

Thanks

 

 

1 ACCEPTED SOLUTION
amitchandak
Super User
Super User

Week of last year is 364 days behind. So if you create a trailing measure with 364 days behind with date calendar you will get. Also, refer to my file where I have used Rank for this week vs last week. In the case of Rank, Last year is 52 weeks behind.

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

https://www.dropbox.com/s/d9898a48e76wmvl/sales_analytics_weekWise.pbix?dl=0

 

To get the best of the time intelligence function. Make sure you have a date calendar and it has been marked as the date in model view. Also, join it with the date column of your fact/s. Refer :
https://radacad.com/creating-calendar-table-in-power-bi-using-dax-functions
https://www.archerpoint.com/blog/Posts/creating-date-table-power-bi
https://www.sqlbi.com/articles/creating-a-simple-date-table-in-dax/

 

If you need more help mark me @

Appreciate your Kudos.

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

View solution in original post

1 REPLY 1
amitchandak
Super User
Super User

Week of last year is 364 days behind. So if you create a trailing measure with 364 days behind with date calendar you will get. Also, refer to my file where I have used Rank for this week vs last week. In the case of Rank, Last year is 52 weeks behind.

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

https://www.dropbox.com/s/d9898a48e76wmvl/sales_analytics_weekWise.pbix?dl=0

 

To get the best of the time intelligence function. Make sure you have a date calendar and it has been marked as the date in model view. Also, join it with the date column of your fact/s. Refer :
https://radacad.com/creating-calendar-table-in-power-bi-using-dax-functions
https://www.archerpoint.com/blog/Posts/creating-date-table-power-bi
https://www.sqlbi.com/articles/creating-a-simple-date-table-in-dax/

 

If you need more help mark me @

Appreciate your Kudos.

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
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

Dec Fabric Community Survey

We want your feedback!

Your insights matter. That’s why we created a quick survey to learn about your experience finding answers to technical questions.

ArunFabCon

Microsoft Fabric Community Conference 2025

Arun Ulag shares exciting details about the Microsoft Fabric Conference 2025, which will be held in Las Vegas, NV.

December 2024

A Year in Review - December 2024

Find out what content was popular in the Fabric community during 2024.