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
YuanG
Helper I
Helper I

Show data by week number

 

Hi Everyone,

 

I'm working on a line chart with some data calcul by week ,and i want the data not show  in format dd/mm/yyyy, but with the number of weeks in year. Like this chart, in 27 June 2016, i want it could show 'week 27'

Sans titre.png

 

I've try with the number of weeks, but it can't figure like a date format. Also i try to show the week number in tooltips, but it can't works with character data,  it's not bed if i could have the week number in tooltips.

 

Thank you in advance!

1 ACCEPTED SOLUTION
kcantor
Community Champion
Community Champion

@YuanG

The calendar is separate and more useful that way. In fact, having your week numbers in your fact table may be throwing off the calculation and sort. While I don't have time to fully explain this, at this time, I wanted to at least respond and share a link that could help.

https://www.sqlbi.com/articles/week-based-time-intelligence-in-dax/





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




View solution in original post

18 REPLIES 18
Eric_Zhang
Employee
Employee

@YuanG

 

Add a calculated column

Week = WEEKNUM([Date])

Create a measure and add it to the Tooltips field.

WeekNum = AVERAGE(Table[Week])

Then you will see the week number when hovering on the visual.

Capture.PNG

Hi @Eric_Zhang

 

Thank you, it works!

And i've found a new problem, it's about a mistake of the week number.

 

Like in the chart below, when i see with all the date, the week of 28 dec 2015 should be the week 53, but here it show 44, and there is no first week of 2016, it start from the second week, normaily the week of 4 jan 2016 should be the the first week of 2016.

1.png

1.png

2.png

 

 

And when i show the data by years, it seperate the week 53 of 2015 in week 53 of 2015 and week 1 of 2016, which they should be the week 53 of 2015

 

3.png4.png

 

Do you know maybe how can i correct this?

Greg_Deckler
Super User
Super User

Not quite clear on the issue but you can create a week number from a date field using a calculated column such as:

 

WeekNum = WEEKNUM([Date])

Then you can create a column like:

 

Week = "Week " & [WeekNum]

Set your sort by for this column to the "WeekNum" column and then use the "Week" column in you Axis.

 

 


@ 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!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...

Hello,

 

Hope you can help me.

What if I need to sort weeks from different years ?

 

Example _

 

2016 (WK) 51- 2016 (WK) 52 - 2017 (WK) 1 - 2017 ( WK) 2 ) ...Sort problems started when I upload data for 2017 (WK )10 

 

Now sort is showing as below :

 

201651 -201652 - 201701-201710-20172-20173-20174 ....

 

Hope you can help me to resolve it ..I tried everything..!!

Have you been able to resolve this? I am having the same issue sorting weeknumbers across multiple years.

 

 

I was able to resolve this by adding the following column to my data table and then sorting in default order.

 

"WorkWeek",  YEAR([date]) &  format(WEEKNUM ( [Date] ),"00")  

Anonymous
Not applicable

can you explain a bit more how you did it?

Have you been able to resolve this? I am having the same issue sorting weeknumbers across multiple years.

 

 

I follow what you advised below, however, what if I have data from different years?? Sort I have been trying is not working ..for example : I have 2016- (WK)51 /2016-(WK)52 / 2017-(WK)1 / 2017-(WK)2 ...as soon I uploaded 2017- (WK)10 problems started.. Now the sort is showing : 2016-51 / 2016-52 / 2017-1 /2017-10 / 2017-2.... Would you please advise how to resolve it ?

Hi @Greg_Deckler

 

First of all, thanks for the reponse.

With the column Week, when i creat a line chart, it will not in the right ordre, i've try to make the week number in type character, but it not works, so do you know how can i do with this?

Sans titre.png

@YuanG - Select your Week column to have a "Sort By" of your WeekNum column.


@ 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!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...

@Greg_Deckler

 

i've try with the sort by, it's not correct neither, and the order is weird

 

Sans titre.png

Is your WeekNum column set to numeric?


@ 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!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...

@Greg_Deckler Yes, it's numeric. I try with the character it's the same. And i have another question, if the weeks are in right order, it will be like week 1 to week 53, but in fact my data start at week 28 of 2015, so is that possibe in my line chart, the x axe will show in date order? Like week 28 of 2015 to week 53 of  2015 and then weeks of 2016

kcantor
Community Champion
Community Champion

@YuanG

Are you creating the Weeknumber field in your date calendar or in your fact table? Add it to your date table.

As for why Jan starts at week 2, look into ISO weeks versus the different "standards" of labeling weeks.  You may need to quantify a 'series' number to determine which week number is assigned due to which day of the week the year starts on or how many days are required to call it a week.

I use a calendar table with both week numbers and ISO week numbers included for that reason. Here is a snip of my calendar. Notice how the ISO week number is different? I added many years to show that, I don't usually use that large of a date table.

DateKeyDateIntYearKeyHalfYearKeyQuarterKeyMonthKeyMonthOfYearQuarterOfYearDayOfYearDayOfMonthDayOfWeekMonDayOfWeekSunMonthYearWeekNumberWeekOfYearISO
12/28/1948194812281948194821948419481212436328231219485353
12/30/2082208212302082208222082420821212436430341220825353
12/28/2065206512282065206522065420651212436228121220655353
12/30/1998199812301998199821998419981212436430341219985353
12/28/1981198112281981198121981419811212436228121219815353
1/2/205520550102205520551205512055111226712055153
1/3/204920490103204920491204912049111337112049153
12/30/1914191412301914191421914419141212436430341219145353
1/2/197119710102197119711197111971111226711971153
12/27/2088208812272088208822088420881212436227121220885353
1/3/196519650103196519651196511965111337111965153
12/27/2004200412272004200422004420041212436227121220045353
12/31/2048204812312048204822048420481212436631451220485353
12/27/1920192012271920192021920419201212436227121219205353
12/31/1964196412311964196421964419641212436631451219645353
12/31/2071207112312071207122071420711212436531451220715353
12/29/2054205412292054205422054420541212436329231220545353
12/31/1987198712311987198721987419871212436531451219875353
12/29/1970197012291970197021970419701212436329231219705353
1/3/204420440103204420441204412044111337112044153
1/1/202720270101202720271202712027111115612027153
1/2/202120210102202120211202112021111226712021153
12/31/1903190312311903190321903419031212436531451219035353
1/3/196019600103196019601196011960111337111960153
1/1/194319430101194319431194311943111115611943153




Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




Hi @kcantor

 

Thanks for the response. 

Sorry i don't really understand the date table things. I just have one table in my dataset, and the date is one column in format dd/mm/yyyy, then I creat a column of week number.  So the date table is a new table i have to creat or it's in somewhere i just need to correct?

kcantor
Community Champion
Community Champion

@YuanG

The calendar is separate and more useful that way. In fact, having your week numbers in your fact table may be throwing off the calculation and sort. While I don't have time to fully explain this, at this time, I wanted to at least respond and share a link that could help.

https://www.sqlbi.com/articles/week-based-time-intelligence-in-dax/





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




Thank you so much!!! @kcantor

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.