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

Earn a 50% discount on the DP-600 certification exam by completing the Fabric 30 Days to Learn It challenge.

Reply
DeonDP
Helper II
Helper II

Weekly bar chart not sorting by date slicer order between years - 2020 & 2021

Hey All

 

This is an easy one for the clever guys on the forum.

 

My weekly bar chart always starts at 0 - 52.

 

So the project I am involved in started in Oct 2020 and is continuing up to today in 2021.

 

When I select 1/10/20 - 31/3/21 in my date slicer, I get a bar chart that looks like this:

 

DeonDP_0-1615335943139.png

 

The first couple of weeks is actually 2021 but it looks really wierd.  How do I get the bar chart to start from the date selected in the slicer?

 

I think it may need to make the change in my DimmDate table by adding a column that uses the correct order taking the week of the calendar year consideration.

 

This is what I am currently using:

 

DeonDP_1-1615336321081.png

 

Your help with this one will be appreciated.

3 ACCEPTED SOLUTIONS

@DeonDP 

you can use DAX to create a column(not in PQ). you need to modify the DAX since I used my own data

Column = year('Dates'[Date])&"-"&WEEKNUM('Dates'[Date])

 1.PNG

 





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

Proud to be a Super User!




View solution in original post

@DeonDP 

you can make 5 to be 05

Column = year(Dates[Date])&"-"&right("0"&WEEKNUM('Dates'[Date]),2)

1.PNG





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

Proud to be a Super User!




View solution in original post

@DeonDP 

have you tried sort by column and sort asc?

1.PNG

 

it should work

 

2.PNG





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

Proud to be a Super User!




View solution in original post

11 REPLIES 11
DeonDP
Helper II
Helper II

Hi Ryan

 

Thanks for your reply.  I am having a hard time to create the column.  Do I create it in Power Query or will i be a DAX formula?

 

I am thinking Power Query - could you please assist with the M Code in Power Query or DAX formula?

 

Thanks

 

D

@DeonDP 

you can use DAX to create a column(not in PQ). you need to modify the DAX since I used my own data

Column = year('Dates'[Date])&"-"&WEEKNUM('Dates'[Date])

 1.PNG

 





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

Proud to be a Super User!




Hi Ryan

 

You have answered my initial question - thanks for that, but there is another level that I need help with.  When I add the two values together with DAX, ie: 

 

to use your graph above: 2014-5 is week 5 and 2014-49 is week 49.  In the viualization however week 5 is displayed after week 49.  I know it has to do with the fact that there is no 0 before the 5, and therefore all 1's, 2's, 3's, etc get sorted by the first number.

 

How do I get the graph to sort it in proper year-week order.  I have seen a video some time ago where the presenter explains how it's done, but I just cannot remember where I saw it for the life of me.

 

Maybe just a FORMAT addition to the DAX formula will resolve the problem.

 

I am fairly new to Power BI, so still have heaps to learn.

 

Cheers

 

Deon

@DeonDP 

you can make 5 to be 05

Column = year(Dates[Date])&"-"&right("0"&WEEKNUM('Dates'[Date]),2)

1.PNG





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

Proud to be a Super User!




I am still getting a weird sort order in my graph.

 

DeonDP_1-1615450899349.png

 

and there should be more weeks as my date slicer indicates:

 

DeonDP_2-1615450958590.png

 

 

 

Could it be because it is text?

@DeonDP 

have you tried sort by column and sort asc?

1.PNG

 

it should work

 

2.PNG





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

Proud to be a Super User!




Awesome!!

 

Thanks for your help Ryan

 

D

ryan_mayu
Super User
Super User

@DeonDP 

try to create a year-week column(e.g. 201050, 202102) and display that on x-axis.





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

Proud to be a Super User!




Hey Ryan

 

Looks like the problem is that

 

Year Week = YEAR(DimDate[DateValue])&"-"&RIGHT("0"&WEEKNUM(DimDate[WeekofYearNo]),2)
 

WEEKNUM part of the DAX formula is returning the week of the month and not the week of the year, so all week 4 of the month weeks are bunched together, and so on.

@DeonDP 

WEEKNUM function (DAX) - DAX | Microsoft Docs

Returns the week number for the given date and year according to the return_type value. The week number indicates where the week falls numerically within a year.

 

based on the screenshot I provided, you can also see 2013-52 and 2013-53

 





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

Proud to be a Super User!




Hi Ryan

 

DAX formula ended up looking like this:

 

Year Week = RIGHT(YEAR(DimDate[DateValue]),2)&"-"&RIGHT("0"&(DimDate[WeekofYearNo]),2)
 
DeonDP_1-1615523259906.png

 

Also had to play around with the sorting to get the graph displaying in the correct order.

 

Thanks again for your help - much appreciated

 

Cheers

 

Deon

 
 
 
 
 

 

 
 

 

 

 

 

 

 

 

 

 

 

Helpful resources

Announcements
LearnSurvey

Fabric certifications survey

Certification feedback opportunity for the community.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.