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
msylv13
Helper I
Helper I

Help with Calendar Week Numbers - No Date

Hello, 

 

I have a dataset that provides the calendar week number (i.e. 1 thru 52) and the year. With this data I am facing two issues. First, I have visuals with the week numbers as the x-axis values. I will need these to display week 1 after week 52 when the next year begins and am not sure how to build that capability. The other problem I am facing is that I have created a measure for calculating the rolling 4 week average based upon the week number. Essentially, this measure ranks the week numbers in descending order and calculates from there. I assume it will fail when week 1 of next year becomes available. Here is a sample DAX for the rolling average:

CFS_4wk_num =
VAR MyIndex =  selectedvalue('Rolling Table'[Index])
VAR myResult =
    AVERAGEX(
        FILTER(
            ALL('Rolling Table'),
            'Rolling Table'[Index] > MyIndex-4  &&
            'Rolling Table'[Index] <= MyIndex
           ),'Rolling Table'[CFS]
           )
RETURN FIXED(myResult,2)    




Any help would be greatly appreciated! I can provide additional context as needed. 

1 ACCEPTED SOLUTION
v-jianboli-msft
Community Support
Community Support

Hi @msylv13 ,

 

Based on your description, I have created a simple sample:

vjianbolimsft_1-1661912347858.png

 

Please try:

Column =
VAR _a =
    AVERAGEX (
        FILTER (
            'Rolling Table',
            [Index] <= EARLIER ( 'Rolling Table'[Index] )
                && [Index]
                    > EARLIER ( 'Rolling Table'[Index] ) - 4
                && [Year] = EARLIER ( 'Rolling Table'[Year] )
        ),
        [CFS]
    )
VAR _b =
    IF (
        [Index] >= 4,
        _a,
        AVERAGEX (
            FILTER (
                'Rolling Table',
                ( [Year] * 100 + [Index] )
                    > (
                        ( EARLIER ( 'Rolling Table'[Year] ) - 1 ) * 100 + 48
                            + EARLIER ( 'Rolling Table'[Index] )
                    )
                    && ( [Year] * 100 + [Index] )
                        <= (
                            EARLIER ( 'Rolling Table'[Year] ) * 100
                                + EARLIER ( 'Rolling Table'[Index] )
                        )
            ),
            [CFS]
        )
    )
RETURN
      _b

change the format:

vjianbolimsft_2-1661912761967.png

 

Output:

vjianbolimsft_3-1661912780791.png

 

Then apply it to the visual:

vjianbolimsft_5-1661912856126.png

 

Final output:

vjianbolimsft_4-1661912841731.png

 

Best Regards,

Jianbo Li

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

6 REPLIES 6
v-jianboli-msft
Community Support
Community Support

Hi @msylv13 ,

 

Based on your description, I have created a simple sample:

vjianbolimsft_1-1661912347858.png

 

Please try:

Column =
VAR _a =
    AVERAGEX (
        FILTER (
            'Rolling Table',
            [Index] <= EARLIER ( 'Rolling Table'[Index] )
                && [Index]
                    > EARLIER ( 'Rolling Table'[Index] ) - 4
                && [Year] = EARLIER ( 'Rolling Table'[Year] )
        ),
        [CFS]
    )
VAR _b =
    IF (
        [Index] >= 4,
        _a,
        AVERAGEX (
            FILTER (
                'Rolling Table',
                ( [Year] * 100 + [Index] )
                    > (
                        ( EARLIER ( 'Rolling Table'[Year] ) - 1 ) * 100 + 48
                            + EARLIER ( 'Rolling Table'[Index] )
                    )
                    && ( [Year] * 100 + [Index] )
                        <= (
                            EARLIER ( 'Rolling Table'[Year] ) * 100
                                + EARLIER ( 'Rolling Table'[Index] )
                        )
            ),
            [CFS]
        )
    )
RETURN
      _b

change the format:

vjianbolimsft_2-1661912761967.png

 

Output:

vjianbolimsft_3-1661912780791.png

 

Then apply it to the visual:

vjianbolimsft_5-1661912856126.png

 

Final output:

vjianbolimsft_4-1661912841731.png

 

Best Regards,

Jianbo Li

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Works perfectly as far as I can tell. Thank you!

v-jianboli-msft
Community Support
Community Support

Hi @msylv13 ,

 

Could you tell me if your problem has been solved? If it is, kindly Accept it as the solution. More people will benefit from it. Or if you are still confused about it, please provide me with more details about your table and your problem or share me with your pbix file after removing sensitive data.

 

Refer to:

How to provide sample data in the Power BI Forum

How to Get Your Question Answered Quickly

 

Best Regards,

Jianbo Li

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

The question regarding the visual was solved. However, I am still searching for support on my question regarding the DAX in my measure. 

Syk
Super User
Super User

You can put both the Year and Week number in the x-axis then expand the data by clicking the highlighted button in the screenshot. Make sure to sort your axis by the year/week number and set to ascending to see it as expected!

Syk_0-1660585744518.png

 

Thank you! This works perfectly. I do still have a remaining issue to solve in my initial post, so I am unsure if I shold mark this as a solution. 

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.