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

Get Fabric Certified for FREE during Fabric Data Days. Don't miss your chance! Request now

Reply
Anonymous
Not applicable

How to make Year and Week as a Date with Direct Query

Hey everyone,

 

I have a requirement where users want to see a KPI on a line chart with the axis of WEEKNUM & YEAR.

 

I'm bringing in a value called "Week Year" where im concattenating year and week together in a sql query.

concat( concat(year(date),'-'), week(date)) as "WeekYear".

 

So you would see each year with 1 through 52/53 weeks.

 

Values basically look like:

 

2020-01 - > 1st week of 2020

2020-02 -> 2nd week of 2020

2020-52 -> 52nd week of 2020

 

 

Power BI reads it as a Text. But I need a way to plot this on the x axis. FORMAT does not work since im using SAP HANA Direct query. 

 

Anyone have a solution?

3 REPLIES 3
v-xuding-msft
Community Support
Community Support

Hi @Anonymous ,

 

May I ask why you don't use the original date column in data source on x-axis?  Time intelligence capabilities are unavailable in DirectQuery. For example, special treatment of date columns (such as year, quarter, month, or day) isn't supported in DirectQuery mode. So if you create a date column based on your "WEEKNUM & YEAR",  the report connection mode will be changed to mixed (Direct query + import). 

https://docs.microsoft.com/en-us/power-bi/connect-data/desktop-use-directquery#limitations-of-directquery

 

If the problem is caused by sorting "WEEKNUM & YEAR" order,  maybe you could get some ideas from this video: https://www.youtube.com/watch?v=n_gnuFS8qoY&feature=youtu.be.

 

 

 

Best Regards,
Xue Ding
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 , while direct query has limitation what can work

You can create date from a week like

Week to Date = var _st = date(left([Week],4),1,1)
var _week = right([Week],2)*1
Return _st+((_week-1)*7) -WEEKDAY(_st,2)+1

 

In your case 

Week to Date = var _st = date([year],4),1,1)
var _week = [Week]
Return _st+((_week-1)*7) -WEEKDAY(_st,2)+1

 

refer the blog.: https://medium.com/@amitchandak.1978/power-bi-wtd-questions-time-intelligence-4-5-98c30fab69d3

you can have date/week table in power bi (mix mode) and use that to deal with week

refer this : https://youtu.be/24arfrD3Qzk

 

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
Greg_Deckler
Community Champion
Community Champion

@Anonymous - Can you just keep them separate and use drill down? Otherwise, can you just concatenate them with "" instead of "-"?



Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
DAX For Humans

DAX is easy, CALCULATE makes DAX hard...

Helpful resources

Announcements
November Power BI Update Carousel

Power BI Monthly Update - November 2025

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

Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.

Top Solution Authors