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

Earn a 50% discount on the DP-600 certification exam by completing the Fabric 30 Days to Learn It challenge.

Reply
fitapbi
New Member

How to set weekly range and weekly variation (M or DAX)

Hi! I have this table for subscriptions to our service:

Id SubscriberSubscription date
21065130/04/2013
21065130/04/2013
21065130/04/2020
22437627/01/2020
22437907/05/2020
22437716/07/2020
22438223/02/2020
22438029/05/2020
22438101/12/2021
21403124/11/2021
21404816/11/2021
21403208/03/2021
21403012/08/2021

 

We are not able to create this output:

Week rangeSubscription 2021
(A)
Weekly variation 2021Subscription 2022
(B)
Weekly variation 20222021 vs 2021
(B-A)/A
1-jan-8-jan3.280 8.387  
9-jan-15-jan4.06123,81%9.88117,81%143,31%
16-jan-22-jan6.91670,30%11.88420,27%71,83%
23-jan-29-jan8.46022,33%13.17410,85%55,72%
30-jan-5-feb9.79815,82%13.8945,47%41,80%
6-feb-12-feb10.6879,07%14.7496,15%38,01%
13-feb-19-feb11.3316,03%15.4754,92%36,57%
20-feb-26-feb11.6612,91%16.0393,64%37,54%
26-feb-5-mar11.9632,59%16.5643,27%38,46%
6-mar-12-mar12.2462,37%17.0633,01%39,34%
13-mar-19-mar12.4932,02%17.5042,58%40,11%
20-mar-26-mar13.0134,16%17.8371,90%37,07%

 

I appreciate solutions both in Query editor (creating a new table) or in DAX

 

Thank you

2 REPLIES 2
v-jianboli-msft
Community Support
Community Support

Hi @fitapbi ,

 

Could you tell me if your problem has been solved? If it is, kindly Accept it as the solution. More people will benefit from it. Or if you are still confused about it, please provide me with more details about your table and your problem(Such as how to calculate the weekly variation and where does the ssubscription come from) or share me with your pbix file after removing sensitive data.

 

Refer to:

How to provide sample data in the Power BI Forum

How to Get Your Question Answered Quickly

 

Best Regards,

Jianbo Li

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

@fitapbi , Create a calendar like below, Join with your table , mark as date table

 

 

Date= 
Var _cal = Addcolumns(calendar(date(2020,01,01), date(2021,12,31) ), "Month no" , month([date]) 
, "Year", year([date])
, "Month Year", format([date],"mmm-yyyy") 
, "Month year sort", year([date])*100 + month([date])
, "Qtr Year", format([date],"yyyy-\QQ") 
, "Qtr", quarter([date]) 
, "Month",FORMAT([Date],"mmmm")
, "Month sort", month([DAte])
, "Week No" , if([Date]> Date(Year([Date]),1,1) ,  Quotient(datediff(Date(Year([Date]),1,2) , [Date], day) ,7)+1 ,1)
, "Year Week" ,Year([Date])*100 + if([Date]> Date(Year([Date]),1,1) ,  Quotient(datediff(Date(Year([Date]),1,2) , [Date], day) ,7)+1 ,1)
			
)
return 
addcolumns(_cal ,
"Week Rank" , rankx(_cal, [Year week],,asc,dense) ,
"Week Name" , format(minx(filter(_cal,[Year Week] =earlier([Year Week])),[Date]), "dd-Mmm") &" - "& format(maxx(filter(_cal,[Year Week] =earlier([Year Week])),[Date]), "dd-Mmm")
)

 

 

 

Then create measure like

 

example

 

This Week = CALCULATE(count(Table[Id Subscriber]), FILTER(ALL('Date'),'Date'[Week Rank]=max('Date'[Week Rank])))
Last Week = CALCULATE(count(Table[Id Subscriber]), FILTER(ALL('Date'),'Date'[Week Rank]=max('Date'[Week Rank])-1))

 

diff = [This Week] - [Last week]

 

diff % =divide( [This Week] - [Last week],[Last week])

 

Use matrix visual with week name in row, year in column , count measure and diff% measure in values

 

Time Intelligence, DATESMTD, DATESQTD, DATESYTD, Week On Week, Week Till Date, Custom Period on Period,
Custom Period till date: https://youtu.be/aU2aKbnHuWs&t=145s

 

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

Helpful resources

Announcements
LearnSurvey

Fabric certifications survey

Certification feedback opportunity for the community.

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.