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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
Anonymous
Not applicable

Calendar table causing problems.

Hi all,

 

I have tried different calendar tables out there, but none seem to help me with matching the data i have.

 

I basically have a table with sales data per week and year, but Power BI treat my week number as "whole numbers", and if i change the data type to "date" then it turns into some 1900s years.

 

If i keep the week number as numbers and try to match it with week number from my calendar table then it fails.

 

cap2.PNG

 

Capture.PNGcap3.PNG

here is my calendar table formula:

 

Date =
ADDCOLUMNS (
CALENDAR (DATE(2015;1;1); DATE(2021;12;31));
"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" )
)

 

 

 

 

Please help.

 

best,

Jakob

 

1 ACCEPTED SOLUTION

Hi @Anonymous,

 

My code is not M code (power query language) it is a DAX formula to calculate a new column in your sales table.

 

1. Go to the "Data" tab (icon looks like a table in the menu in the left side) (Don't enter "Edit Queries")

2. Go to your table with your sales transactions

3. On the "Home" tab in the top menu select "New Column" under "Calculations" (just to the left of the Publish button)

4. Insert this code in the formula field "FirstDayOfWeek = DATE([Year];1;-2) - WEEKDAY(DATE([Year];1;3)) + [Week_number]*7" (and press enter)

 

You now have a new column in your sales table the should hold the first date of the week calculated from your year and week column and you should be able to make a relationship between this column and your date column in your calendar table.

 

 

/sdjensen

View solution in original post

16 REPLIES 16

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

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.