cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Highlighted
Helper III
Helper III

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:

 

1 ACCEPTED SOLUTION

Accepted Solutions
Highlighted
Community Support
Community Support

Re: Direct Query - Start of the Week Date

Hi, @Neill_ 

 

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.

 

 

View solution in original post

3 REPLIES 3
Highlighted
Helper III
Helper III

Re: Direct Query - Start of the Week Date

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

Highlighted
Super User IV
Super User IV

Re: Direct Query - Start of the Week Date

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



Did I answer your question? Mark my post as a solution! Appreciate your Kudos!!
My Recent Blog -Week is not so Weak Connect on Linkedin

Proud to be a Super User!

Highlighted
Community Support
Community Support

Re: Direct Query - Start of the Week Date

Hi, @Neill_ 

 

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.

 

 

View solution in original post

Helpful resources

Announcements
Community Blog

Community Blog

Visit our Community Blog for articles, guides, and information created by fellow community members.

Using the Community

Using the Community

Need help with the Power BI Community? Our 'Using the Community' support articles are a great place to start.

Community Summit North America

Community Summit North America

Innovate, Collaborate, Grow. The top training and networking event across the globe for Microsoft Business Applications

Power Platform 2020 release wave 2 plan

Power Platform 2020 release wave 2 plan

Features releasing from October 2020 through March 2021

Top Solution Authors
Top Kudoed Authors