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

Power BI is turning 10! Let’s celebrate together with dataviz contests, interactive sessions, and giveaways. Register now.

Reply
Mous007
Helper IV
Helper IV

Date table sorting error

Hi everyone,

 

The extract of my current dates table:

DatesTable =
VAR MinYear = YEAR ( MIN ( 'Power BI users extract'[Date] ) )
VAR MaxYear = YEAR ( MAX ( 'Power BI users extract'[Date] ) )
RETURN
ADDCOLUMNS (
FILTER (
CALENDARAUTO( ),
AND ( YEAR ( [Date] ) >= MinYear, YEAR ( [Date] ) <= MaxYear )),
"Calendar Year", YEAR ( [Date] ),
"Month Name", FORMAT ( [Date], "MMM" ),
"Month Number", MONTH ( [Date] ),
"Weekday", FORMAT ( [Date], "ddd" ),
"Weekday number", WEEKDAY( [Date] ),
"Period", FORMAT( [Date], "MMM-YYYY" ),
"Week number" , WEEKNUM([Date], 2),
"Week", "W" & FORMAT( [Date], "WW-MMM-YY" ),
"Quarter", "Q" & TRUNC ( ( MONTH ( [Date] ) - 1 ) / 3 ) + 1)
 
The table below is showing the report views count per week:
 

weekserrorsorting.png

 

So i have managed to create a date table with the help of other users and everything was fine untill i tried to sort one of my tables based on the week value. i tried to sort by week both ascending descending and im not getting the correct sorting. The only waz i can get it to work is when i add the week number to my table and the issue with this approach is on the following screenshot. Power bi is putting the last weeks of 2019 after the first weeks of 2020.

 

weeknumbererror.png

I would appreciate if anyone has an idea on how to tackle this issue.

 

Thanks in advance

 

1 ACCEPTED SOLUTION
Greg_Deckler
Super User
Super User

Perhaps Sequential? 

https://community.powerbi.com/t5/Quick-Measures-Gallery/Sequential/m-p/380231#M116

 



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!:
Power BI Cookbook Third Edition (Color)

DAX is easy, CALCULATE makes DAX hard...

View solution in original post

2 REPLIES 2
Greg_Deckler
Super User
Super User

Perhaps Sequential? 

https://community.powerbi.com/t5/Quick-Measures-Gallery/Sequential/m-p/380231#M116

 



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!:
Power BI Cookbook Third Edition (Color)

DAX is easy, CALCULATE makes DAX hard...

Hello there @Greg_Deckler , thanks a lot for your prompt reply.

 

I have tried to following column based on your link but it seems that its not working;

 

Column =
VAR MaxWeeks = SUMMARIZE(ALL('DatesTable'[Week number]),'DatesTable'[Week number],"MaxWeek",MAX('DatesTable'[Week number]))
VAR MyYear = [Calendar Year]
VAR MyStart = SUMX(FILTER(MaxWeeks,[Calendar Year]<MyYear),[MaxWeek])
VAR firstYear = CALCULATE(FIRSTNONBLANK('DatesTable'[Calendar Year],1),ALL(DatesTable[Week number]))
VAR myNum = IF(MyYear=firstYear,[Week number],MyStart+[Week number])
RETURN myNum
 
and my table is still returning the following;
 
sequential dates.png
maybe i am not using your technique correctly or i have made an error in my dax.
 
Any recommendations would be appreciated.

Helpful resources

Announcements
June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

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

June 2025 community update carousel

Fabric Community Update - June 2025

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