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
dexter
Helper II
Helper II

creating a calculated column in the Date table

I have the below Date table, i want to add a new column which shows startOftheWeek date(in my case start of the week should be every thursday).
How can i calculate the start of the week(every thursday) and show that in the newly created column in the Date table below.

 

Date =
ADDCOLUMNS (
CALENDARAUTO ();
"DateAsInteger"; FORMAT ( [Date]; "YYYYMMDD" );
"Year"; YEAR ( [Date] );
"Monthnumber"; FORMAT ( [Date]; "MM" );
"YearMonthnumber"; FORMAT ( [Date]; "YYYY/MM" );
"YearMonthShort"; FORMAT ( [Date]; "YYYY/mmm" );
"MonthNameShort"; FORMAT ( [Date]; "mmm" );
"MonthNameLong"; FORMAT ( [Date]; "mmmm" );
"DayOfWeekNumber"; WEEKDAY ( [Date] );
"DayOfWeek"; FORMAT ( [Date]; "dddd" );
"DayOfWeekShort"; FORMAT ( [Date]; "ddd" );
"Quarter"; "Q" & FORMAT ( [Date]; "Q" );
"YearQuarter"; FORMAT ( [Date]; "YYYY" ) & "/Q" & FORMAT ( [Date]; "Q" )
)
1 ACCEPTED SOLUTION
Chihiro
Solution Sage
Solution Sage

Something like below. Apply formatting as required.

 

Date =
ADDCOLUMNS (
CALENDARAUTO ();
"DateAsInteger"; FORMAT ( [Date]; "YYYYMMDD" );
"Year"; YEAR ( [Date] );
"Monthnumber"; FORMAT ( [Date]; "MM" );
"YearMonthnumber"; FORMAT ( [Date]; "YYYY/MM" );
"YearMonthShort"; FORMAT ( [Date]; "YYYY/mmm" );
"MonthNameShort"; FORMAT ( [Date]; "mmm" );
"MonthNameLong"; FORMAT ( [Date]; "mmmm" );
"DayOfWeekNumber"; WEEKDAY ( [Date] );
"DayOfWeek"; FORMAT ( [Date]; "dddd" );
"DayOfWeekShort"; FORMAT ( [Date]; "ddd" );
"Quarter"; "Q" & FORMAT ( [Date]; "Q" );
"YearQuarter"; FORMAT ( [Date]; "YYYY" ) & "/Q" & FORMAT ( [Date]; "Q" );
"startOftheWeek"; [Date] - WEEKDAY ( [Date], 14) + 1
)

View solution in original post

6 REPLIES 6
Chihiro
Solution Sage
Solution Sage

Something like below. Apply formatting as required.

 

Date =
ADDCOLUMNS (
CALENDARAUTO ();
"DateAsInteger"; FORMAT ( [Date]; "YYYYMMDD" );
"Year"; YEAR ( [Date] );
"Monthnumber"; FORMAT ( [Date]; "MM" );
"YearMonthnumber"; FORMAT ( [Date]; "YYYY/MM" );
"YearMonthShort"; FORMAT ( [Date]; "YYYY/mmm" );
"MonthNameShort"; FORMAT ( [Date]; "mmm" );
"MonthNameLong"; FORMAT ( [Date]; "mmmm" );
"DayOfWeekNumber"; WEEKDAY ( [Date] );
"DayOfWeek"; FORMAT ( [Date]; "dddd" );
"DayOfWeekShort"; FORMAT ( [Date]; "ddd" );
"Quarter"; "Q" & FORMAT ( [Date]; "Q" );
"YearQuarter"; FORMAT ( [Date]; "YYYY" ) & "/Q" & FORMAT ( [Date]; "Q" );
"startOftheWeek"; [Date] - WEEKDAY ( [Date], 14) + 1
)

What does this line do, can you please elloborate. Why are you substracting WEEKDAY([Date],14)+1?

 

"startOftheWeek"; [Date] - WEEKDAY ( [Date], 14) + 1

 

WEEKDAY formula with argument of 14 for pattern returns WEEKDAY number 1 for Thursday, ending with 7 for Wednesday.

So date minus weekday number will give last Wednesday’s date. Add back 1 day and you get week start day of Thursday.

Sorry, i could not understand why are you using 14. As in this link https://msdn.microsoft.com/en-us/query-bi/dax/weekday-function-dax, they specified WEEKDAY(<date>, <return_type>) and return_type is either 1 or 2 or 3.

That documentation isn't complete.

 

Argument can use following values.

1 to 3 and 11 to 17.

11 to 17 is useful when you want week to start on specific weekday.

 

11 = Monday = 1

12 = Tuesday = 1

...

14 = Thursday = 1

...

 

You get the idea.

 

@Chihiro, Can i create a new measure which shows thursday's date as the weekstart date in my existing productTable which has ID,prodName,status,DeliveredDate,Comments as the columns. The before accepted solution is great but we are creating a separate Date table instead of it i just want to create one calculated column or measure in my existing table if possible?

Helpful resources

Announcements
RTI Forums Carousel3

New forum boards available in Real-Time Intelligence.

Ask questions in Eventhouse and KQL, Eventstream, and Reflex.

MayPowerBICarousel

Power BI Monthly Update - May 2024

Check out the May 2024 Power BI update to learn about new features.

LearnSurvey

Fabric certifications survey

Certification feedback opportunity for the community.