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
Igotzepowerbi
Frequent Visitor

Week Number Column Out of Order

Hi, I am having an issue where my week numbers are out of order. Can someone help me with how to order them. I added the formula that is creating the table I am using. I have tried quite a few things with no luck so any help would be really appreciated. THanks so much!

Igotzepowerbi_0-1713880536341.png

 


Igotzepowerbi_0-1713880293850.png

Igotzepowerbi_1-1713880310482.png

DateAutoTemplate =
--  
--     Configuration
--  
VAR __FirstDayOfWeek = 0
----------------------------------------
VAR __WeekDayCalculationType = IF ( __FirstDayOfWeek = 0, 7, __FirstDayOfWeek ) + 10
VAR __Calendar =
    VAR __FirstYear = YEAR ( MINX ( { MIN ( 'POS Aggregate'[Week End Date] ) }, ''[Value] ) )
    VAR __LastYear =  YEAR ( MAXX ( { MAX ( 'POS Aggregate'[Week End Date] ) }, ''[Value] ) )
    RETURN CALENDAR (
        DATE ( __FirstYear, 1, 1 ),
        DATE ( __LastYear, 12, 31 )
    )
VAR __Step3 =
    GENERATE (
        __Calendar,
        VAR __IsStandardLocale = IF ( FORMAT( DATE( 2000, 1, 1 ), "oooo" ) = "oooo", TRUE, FALSE )
        VAR __MonthFormatString = IF( __IsStandardLocale, "mmm", "ooo" )
        VAR __DayFormatString = IF( __IsStandardLocale, "ddd", "aaa" )
        VAR __LastTransactionDate = MAXX ( { MAX ( 'POS Aggregate'[Week End Date] ) }, ''[Value] )
        VAR __Date = [Date]
        VAR __YearNumber = YEAR ( __Date )
        VAR __QuarterNumber = QUARTER ( __Date )
        VAR __YearQuarterNumber = CONVERT ( __YearNumber * 4 + __QuarterNumber - 1, INTEGER )
        VAR __MonthNumber = MONTH ( __Date )
        VAR __WeekDayNumber = WEEKDAY ( __Date, __WeekDayCalculationType )
        VAR __WeekNumber = WEEKNUM ( __Date )
        VAR __WeekNumberYear = WEEKNUM ( __Date, 2 )
        VAR __WeekDay = FORMAT ( __Date, __DayFormatString )
        VAR __WeekEndDate = __Date - MOD ( __Date + 0, 7 ) + 7
        RETURN ROW (
            "Year", __YearNumber,
            "Year Quarter Number", __YearQuarterNumber,
            "Year Quarter", FORMAT ( __QuarterNumber, "\Q0" ) & "-" & FORMAT ( __YearNumber, "0000" ),
            "Quarter", FORMAT( __QuarterNumber, "\Q0" ),
            "Year Month", FORMAT ( __Date, __MonthFormatString & " yyyy" ),
            "Year Month Number", __YearNumber * 12 + __MonthNumber - 1,
            "Month", FORMAT ( __Date, __MonthFormatString ),
            "Month Number", __MonthNumber,
            "Week Number", __WeekNumber,
            "Week Number Year", __WeekNumberYear,  // Adding Week Number Year
            "Day of Week Number", __WeekDayNumber,
            "Day of Week", __WeekDay,
            "DateWithTransactions", __Date <= __LastTransactionDate,
            "Week End Date", __WeekEndDate
        )
    )
RETURN
    __Step3
1 ACCEPTED SOLUTION
audreygerred
Super User
Super User

Right now, it just looks like your chart is sorting by the value (greatest to least) instead of the week number. As long as your week number is set as a number and not a string, click the three dots on your chart, and click sort axis, then select week number. 

audreygerred_0-1713891462281.png

 

As far as your error goes, it is implying that for at least 1 week number, there are multiple different values for that same week in Week Number Year.

 




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

Proud to be a Super User!





View solution in original post

1 REPLY 1
audreygerred
Super User
Super User

Right now, it just looks like your chart is sorting by the value (greatest to least) instead of the week number. As long as your week number is set as a number and not a string, click the three dots on your chart, and click sort axis, then select week number. 

audreygerred_0-1713891462281.png

 

As far as your error goes, it is implying that for at least 1 week number, there are multiple different values for that same week in Week Number Year.

 




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

Proud to be a Super User!





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.