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

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.

Reply
Anonymous
Not applicable

Returning first working date per week

Hello Community,

 

Hope you are well.

 

I have the below calendar table. I need to add a calculated column returning the first working date per week.

 

Any help more than welcomed.

 

DateYearQuarterMonthWeek of YearYear_QuarterYear_MonthYear_WeekDay_NameWorking/Weekend_Day

01/01/202120211112021.Q12021.M012021.W01FriWorking
02/01/202120211112021.Q12021.M012021.W01SatWeekend
03/01/202120211112021.Q12021.M012021.W01SunWeekend
04/01/202120211122021.Q12021.M012021.W02MonWorking
05/01/202120211122021.Q12021.M012021.W02TueWorking
06/01/202120211122021.Q12021.M012021.W02WedWorking
07/01/202120211122021.Q12021.M012021.W02ThuWorking
08/01/202120211122021.Q12021.M012021.W02FriWorking
09/01/202120211122021.Q12021.M012021.W02SatWeekend
10/01/202120211122021.Q12021.M012021.W02SunWeekend
11/01/202120211132021.Q12021.M012021.W03MonWorking
12/01/202120211132021.Q12021.M012021.W03TueWorking
13/01/202120211132021.Q12021.M012021.W03WedWorking
14/01/202120211132021.Q12021.M012021.W03ThuWorking
15/01/202120211132021.Q12021.M012021.W03FriWorking
16/01/202120211132021.Q12021.M012021.W03SatWeekend
17/01/202120211132021.Q12021.M012021.W03SunWeekend
18/01/202120211142021.Q12021.M012021.W04MonWorking
19/01/202120211142021.Q12021.M012021.W04TueWorking
20/01/202120211142021.Q12021.M012021.W04WedWorking
21/01/202120211142021.Q12021.M012021.W04ThuWorking
22/01/202120211142021.Q12021.M012021.W04FriWorking
23/01/202120211142021.Q12021.M012021.W04SatWeekend
24/01/202120211142021.Q12021.M012021.W04SunWeekend
25/01/202120211152021.Q12021.M012021.W05MonWorking
26/01/202120211152021.Q12021.M012021.W05TueWorking
27/01/202120211152021.Q12021.M012021.W05WedWorking
28/01/202120211152021.Q12021.M012021.W05ThuWorking
29/01/202120211152021.Q12021.M012021.W05FriWorking
30/01/202120211152021.Q12021.M012021.W05SatWeekend
31/01/202120211152021.Q12021.M012021.W05SunWeekend
01/02/202120211262021.Q12021.M022021.W06MonWorking

 

Thank you in advance,

 

George

1 ACCEPTED SOLUTION
AlexisOlson
Super User
Super User

If you want a date for each row, then try

FirstWorkdayOfWeek =
CALCULATE (
    MIN ( 'Calendar'[Date] ),
    ALLEXCEPT ( 'Calendar', 'Calendar'[Year], 'Calendar'[Week of Year] )
)

This takes the minimal date in the calendar table for the Year and Week of Year combination in that particular row.

View solution in original post

9 REPLIES 9
Anonymous
Not applicable

Hello all,

 

Thank you very much for your replies. Please see below the outcome of all 4 replies. I decided to flag @AlexisOlson as the preferred solution as I still try to put my mind around the "earlier" function that other users had used at their replies. 

 

GeorgeGiannakis_0-1646147320491.png

 

EARLIER can be a bit confusing if you think it refers to an earlier time when it actually refers to an earlier row context.

 

You can rewrite a version using EARLIER

CALCULATE (
    MIN ( 'Calendar'[Date] ),
    FILTER (
        ALL ( 'Calendar' ),
        'Calendar'[Year_Week] = EARLIER ( 'Calendar'[Year_Week] )
    )
)

using a variable instead

VAR CurrYear_Week = 'Calendar'[Year_Week]
RETURN
    CALCULATE (
        MIN ( 'Calendar'[Date] ),
        FILTER ( ALL ( 'Calendar' ), 'Calendar'[Year_Week] = CurrYear_Week )
    )
Anonymous
Not applicable

thank you @AlexisOlson  for that . There is a very educative vide at Curbal youtube channel explaining earlier. However, I prefer the use of variables as , among other things , provides a clearer picture of how the measure works . Also, the SQLBI team is also in favour of using variables instead of earlier. Going back to your variable example, I believe that the variable reflects the current row, am i correct in reading it like that? thank you

Yes. When rows context exists (like in a calculated column), 'Calendar'[Year_Week] refers to the Year_Week value in the current row.

Hi @Anonymous 

for a calculated column you have a row context. For each row (ech cell of this calculated coulumn), FILTER will iterate over the table creating a new row context inside the earlier one. EARLIER restores the previous raw context and evaluates the expression based on it. 
In your caseEARLIER ( 'Calendar'[Working/Weekend] ) is actually the value of this coulmn at the same row under evaluation. While 'Calendar'[Working/Weekend] will have different values during the iteration of FILTER

Anonymous
Not applicable

Hi @Anonymous ,

 

Please try:

Column = CALCULATE(FIRSTNONBLANK('Table'[Date],TRUE()),FILTER('Table',[Year_Week]=EARLIER('Table'[Year_Week]) && [Working/Weekend_Day]="Working"))

Output:

Eyelyn9_0-1646104603147.png  Eyelyn9_1-1646104638255.png

 

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

AlexisOlson
Super User
Super User

If you want a date for each row, then try

FirstWorkdayOfWeek =
CALCULATE (
    MIN ( 'Calendar'[Date] ),
    ALLEXCEPT ( 'Calendar', 'Calendar'[Year], 'Calendar'[Week of Year] )
)

This takes the minimal date in the calendar table for the Year and Week of Year combination in that particular row.

tamerj1
Super User
Super User

Hi @Anonymous 

Try

MyColumn =
CALCULATE (
VALUES ( 'Calendar'[Working/Weekend] ),
FILTER (
ALL ( 'Calendar' ),
'Calendar'[Year-Week] = EARLIER ( 'Calendar'[Year-Week] )
&& 'Calendar'[Working/Weekend] = EARLIER ( 'Calendar'[Working/Weekend] )
),
'Calendar'[Date] = MIN ( 'Calendar'[Date] )
)

amitchandak
Super User
Super User

@Anonymous ,

NEw column =

if( [Date] =minx(filter(table, [Year_Week] = earlier([Year_Week]) ),[Date]) , True(), false())

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
July 2025 community update carousel

Fabric Community Update - July 2025

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

July PBI25 Carousel

Power BI Monthly Update - July 2025

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