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
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

 


@ 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...

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

 


@ 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 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
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.

Top Solution Authors