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

Need Help! Rolling Week (4 & 13) columns of Volume Measure

Need help powerful brains!

 

I am trying to build a table that shows healthcare professional's TRx (Prescription) volume by rolling 4 week and another column for rolling 13 week, then I want to show the previous 4 week and 13 week so I can monitor progress on them. I have a table that has the Prescription data that comes from IQVIA in weekly buckets instead of days and its connected to my time intelligence table.

 

I have tried using for example the DATEADD function, but it does not work. I do not plan to change dates in this visual tab so the data will refresh once i add the new week of data. Below is a simple view of how the table would look like.

 

Any help is appreciated!!

 

ivargaspr_0-1599427472565.png

 

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

Hi @Anonymous ,

 

Do you want to get the two values, one is previous 4 weeks value, another is previous 13 weeks value.

For example, today is 37th week, so the previous 4 weeks is 33rd week, the previous 13 weeks is 24th week.

 

If yes, you can refer the following two measures.

 

Last 4 week = 
var _current_week = WEEKNUM(TODAY(),2)
var _last_4_week = _current_week - 4
return
CALCULATE(SUM('Table'[value]),FILTER('Table','Table'[Weeknum]=_last_4_week))

 

Last 13 week = 
var _current_week = WEEKNUM(TODAY(),2)
var _last_13_week = _current_week - 13
return
CALCULATE(SUM('Table'[value]),FILTER('Table','Table'[Weeknum]=_last_13_week))

 

need1.jpg

 

If it doesn’t meet your requirement, could you please provide a mockup sample based on fake data or describe the fields of each tables and the relations between tables simply?

It will be helpful if you can show us the exact expected result based on the tables.

 

Please upload your files to OneDrive For Business and share the link here. Please don't contain any Confidential Information or Real data in your reply.

 

Best regards,

 

Community Support Team _ zhenbw

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

 

BTW, pbix as attached.

View solution in original post

6 REPLIES 6
v-zhenbw-msft
Community Support
Community Support

Hi @Anonymous ,

 

Do you want to get the two values, one is previous 4 weeks value, another is previous 13 weeks value.

For example, today is 37th week, so the previous 4 weeks is 33rd week, the previous 13 weeks is 24th week.

 

If yes, you can refer the following two measures.

 

Last 4 week = 
var _current_week = WEEKNUM(TODAY(),2)
var _last_4_week = _current_week - 4
return
CALCULATE(SUM('Table'[value]),FILTER('Table','Table'[Weeknum]=_last_4_week))

 

Last 13 week = 
var _current_week = WEEKNUM(TODAY(),2)
var _last_13_week = _current_week - 13
return
CALCULATE(SUM('Table'[value]),FILTER('Table','Table'[Weeknum]=_last_13_week))

 

need1.jpg

 

If it doesn’t meet your requirement, could you please provide a mockup sample based on fake data or describe the fields of each tables and the relations between tables simply?

It will be helpful if you can show us the exact expected result based on the tables.

 

Please upload your files to OneDrive For Business and share the link here. Please don't contain any Confidential Information or Real data in your reply.

 

Best regards,

 

Community Support Team _ zhenbw

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

 

BTW, pbix as attached.

Anonymous
Not applicable

 

Thanks for your input!.  So I tried recreating the formula, but it came blank. I am looking for the sum of the last 4 weeks so i can do the same with other methods such as the sum of the last 8 weeks and see the delta. Same for the last 13 Weeks and compare them to the previous 13 Weeks (first 13 weeks out of the total 26 weeks) so i can look at up/down trends. 

 

ivargaspr_0-1601322461491.png

 

Anonymous
Not applicable

I was able to make it show values (it was a date filter that was hiding the values). I think I am almost there. The last thing i have to fgure out is that the data has multiple year so right now it is summing all values that have week "36" for example, but i only want week 36 of the current year. 

Hi @Anonymous ,

 

How about the result after you follow the suggestions mentioned in my original post?

Could you please provide more details or expected result about it If it doesn't meet your requirement?

If you've fixed the issue on your own please kindly share your solution. If the above posts help, please kindly mark it as a solution to help others find it more quickly.

 

Best regards,

 

Community Support Team _ zhenbw

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

amitchandak
Super User
Super User

@Anonymous , That depends on how you have week data. So if date or Week Year (202001) or week start date where you can sort and create a rank. This will become easy.

Create a date or Week Table


Week Rank = RANKX(all('Date'),'Date'[Week Start date],,ASC,Dense)  // or on Week Year
This Week = CALCULATE(sum('order'[Qty]), FILTER(ALL('Date'),'Date'[Week Rank]=max('Date'[Week Rank])))
Last Week = CALCULATE(sum('order'[Qty]), FILTER(ALL('Date'),'Date'[Week Rank]=max('Date'[Week Rank])-1))
Last year Week= CALCULATE(sum('order'[Qty]), FILTER(ALL('Date'),'Date'[Week Rank]=(max('Date'[Week Rank]) -52)))

 

Last 4  week Sales = CALCULATE(SUM(Sales[Net Sales]),FILTER(all('Date'),'Date'[Week Rank]>=min('Date'[Week Rank])-4 && 'Date'[Week Rank]<=max('Date'[Week Rank])))

 

Last 13 week Sales = CALCULATE(SUM(Sales[Net Sales]),FILTER(all('Date'),'Date'[Week Rank]>=min('Date'[Week Rank])-13 && 'Date'[Week Rank]<=max('Date'[Week Rank])))

 

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

 

Greg_Deckler
Super User
Super User

@Anonymous - It's a little old and creaky but I did this once: https://community.powerbi.com/t5/Quick-Measures-Gallery/Rolling-Weeks/m-p/391694#M128

Can handling any amount of rolling weeks, 4, 13, etch. If you post sample data as text I can be more specific.


@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...

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.