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

Get Fabric Certified for FREE during Fabric Data Days. Don't miss your chance! Request now

Reply
calexander24
Frequent Visitor

Calculate Weeks with static and Count of selected weeks

Hello,

 

I am trying to calculate a count of 4 seperate sets of weeks, one of which is static and the other is based on the selected week or month. 

Ideally it would look like this, and from there I can run my other calculations. I have a table KeyMeasures that have Schedule 2 & 3 defining the count of weeks but currently i am only returning the weeks that are selected. not the 13 and 4. 

ScheduleWeeks
1Selected weeks last year
213 (Static)
34 (Static)
4Selected weeks this year

 

right now my formula looks like this, 

 

 

PRJ_WKS = DISTINCT(KeyMeasures[WK])

SEL_WKS = DISTINCTCOUNT(Calendar_Table[WK_ST_DATE])

WKS2 = 
VAR RptWeek =
    MAX(Calendar_Table[WK_ST_DATE])
VAR Calc1 =
    CALCULATE(
        [WKS],
        Calendar_Table[CALENDAR_DAY] <= RptWeek)
VAR Project =  CALCULATE([PRJ_WKS],
               ALL(Calendar_Table))
VAR PRJ_2 = CALCULATE(SUM(KeyMeasures[WK]), KeyMeasures[2 SORT] = 2)
VAR PRJ_3 = CALCULATE(SUM(KeyMeasures[WK]), KeyMeasures[2 SORT] = 3)
RETURN
    IF(PRJ_2 = 13,PRJ_2, IF(PRJ_3 = 4,PRJ_3,Calc1))

 

 



1 ACCEPTED SOLUTION
amitchandak
Super User
Super User

@calexander24 , You can use week rank to compare the data and for static you use week number

 

example

 

new columns needed as per need

 

new columns
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

 

example 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)))

 

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

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

View solution in original post

1 REPLY 1
amitchandak
Super User
Super User

@calexander24 , You can use week rank to compare the data and for static you use week number

 

example

 

new columns needed as per need

 

new columns
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

 

example 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)))

 

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

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

Helpful resources

Announcements
November Power BI Update Carousel

Power BI Monthly Update - November 2025

Check out the November 2025 Power BI update to learn about new features.

Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.

Top Solution Authors