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

Direct Query - Start of the Week Date

I'm currently trying to create a page filter for all of my charts in Direct Query.

 

The filter I need is the start of the week date . As I'm using Direct Query I can't manually enter start of the week dates e.g.

 

01/04/20191
08/04/20192
15/04/20193

 

So I've created a datekey via this code:

DateKey = CALENDAR(DATE(2000,01,01),DATE(2050,12,31))
WeekStartDate = DateKey[Date]- WEEKDAY(DateKey[Date],2)+1 // Monday as Week start date
 
However this creates a many to many relationship error with my core data table:
Single SoW date picture.GIF
 
So I have created an additional table (piggybacking off of the datekey to SUMMARIZE the "WeekStartDate" :
 

SoW Index = SUMMARIZE(DateKey, DateKey[WeekStartDate])

Index = RANKX(ALL('SoW Index'),'SoW Index'[WeekStartDate],,ASC)

 

And created a relationship to my core table with this new (piggyback) table:

 

3 REPLIES 3
v-alq-msft
Community Support
Community Support

Hi, @Anonymous 

 

Based on your description, I created data in SQL SERVER to reproudce your scenario.

SOW:

b1.png

 

Then I connected to the data source with Direct Query mode. I created a calculated table and a calculated column as below.

 

Calculated table:
DateKey = CALENDAR(DATE(2019,1,1),DATE(2020,12,31))

Calculated column:
WeekStartDate = DateKey[Date]-WEEKDAY(DateKey[Date],2)+1

 

 

There is a relationship between two tables based on 'Date' column.

 

Result:

b2.png

 

Best Regards

Allan

 

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

@Anonymous , Join SOW of Table with Date of Date Table. Start of Week in calendar/Date will take care of Display

Anonymous
Not applicable

Sow Piggy back.GIF

 

However it's still not working. Can anyone advise on how to build start of the week date tables in Direct Query?

 

Thanks

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.