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

Find everything you need to get certified on Fabric—skills challenges, live sessions, exam prep, role guidance, and more. Get started

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
July 2024 Power BI Update

Power BI Monthly Update - July 2024

Check out the July 2024 Power BI update to learn about new features.

July Newsletter

Fabric Community Update - July 2024

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