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

Earn the coveted Fabric Analytics Engineer certification. 100% off your exam for a limited time only!

Reply
emildeak
Regular Visitor

Grouped by week - determine change

Hi,

 

i have a problem where i stuck since several days, maybe you can help me.

 

I have a table with 2 columns, day and value. I'd like to get the value grouped bei a week Starting on Monday.

And i would like to determine the change of the weekly value compared to the previous week.

WeekDayValueWeek AvgWeekly Change
1Day 116%  
1Day 27%  
1Day 336%  
1Day 411%  
1Day 513%  
1Day 614%  
1Day 724%17%/
2Day 815%  
2Day 941%  
2Day 1029%  
2Day 1145%  
2Day 1243%  
2Day 1322%  
2Day 1418%30%76%

 

 

Thank you in advance, i hope this is possible and there is a way to do this 🙂

 

best regards

Emil

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

Hi @emildeak ,

 

Based on your description, I have created a simple sample:

vjianbolimsft_0-1669959098796.png

Please try:

Week Avg = 
var _a = WEEKDAY(MAX('Table'[Day]),2)
var _b = CALCULATE(AVERAGE('Table'[Value]),FILTER(ALL('Table'),WEEKNUM([Day],2)=WEEKNUM(MAX('Table'[Day]),2)))
return IF(_a=7,_b)

Weekly Change = 
var _a = WEEKDAY(MAX('Table'[Day]),2)
var _b = CALCULATE(SUM('Table'[Value]),FILTER(ALL('Table'),WEEKNUM([Day],2)=WEEKNUM(MAX('Table'[Day]),2)))// the value of current week
var _c = CALCULATE(SUM('Table'[Value]),FILTER(ALL('Table'),WEEKNUM([Day],2)=WEEKNUM(MAX('Table'[Day]),2)-1))// the value of previous week
var _d = DIVIDE(_c,_b)
return IF(_a=7,_d)

Output:

vjianbolimsft_1-1669959139135.png

Since I'm not sure what your weekly change is based on, I calculated the percentage change in their total weekly value. You can change the aggregation in the measure to get the value you want, or clarify your calculation logic to me.

 

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.

View solution in original post

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

Hi @emildeak ,

 

Based on your description, I have created a simple sample:

vjianbolimsft_0-1669959098796.png

Please try:

Week Avg = 
var _a = WEEKDAY(MAX('Table'[Day]),2)
var _b = CALCULATE(AVERAGE('Table'[Value]),FILTER(ALL('Table'),WEEKNUM([Day],2)=WEEKNUM(MAX('Table'[Day]),2)))
return IF(_a=7,_b)

Weekly Change = 
var _a = WEEKDAY(MAX('Table'[Day]),2)
var _b = CALCULATE(SUM('Table'[Value]),FILTER(ALL('Table'),WEEKNUM([Day],2)=WEEKNUM(MAX('Table'[Day]),2)))// the value of current week
var _c = CALCULATE(SUM('Table'[Value]),FILTER(ALL('Table'),WEEKNUM([Day],2)=WEEKNUM(MAX('Table'[Day]),2)-1))// the value of previous week
var _d = DIVIDE(_c,_b)
return IF(_a=7,_d)

Output:

vjianbolimsft_1-1669959139135.png

Since I'm not sure what your weekly change is based on, I calculated the percentage change in their total weekly value. You can change the aggregation in the measure to get the value you want, or clarify your calculation logic to me.

 

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

@emildeak , one of the ways is to have week rank on the year week column, in separate week/date table

 

new column

 

Week Rank RANKX(all('Date'),'Date'[Year Week],,ASC,Dense) //YYYYWW format

 

This Week = CALCULATE(Average('Table'[Value]), FILTER(ALL('Date'),'Date'[Week Rank]=max('Date'[Week Rank])))
Last Week = CALCULATE(Average('Table'[Value]), FILTER(ALL('Date'),'Date'[Week Rank]=max('Date'[Week Rank])-1))

Helpful resources

Announcements
April AMA free

Microsoft Fabric AMA Livestream

Join us Tuesday, April 09, 9:00 – 10:00 AM PST for a live, expert-led Q&A session on all things Microsoft Fabric!

March Fabric Community Update

Fabric Community Update - March 2024

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