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

Don't miss out! 2025 Microsoft Fabric Community Conference, March 31 - April 2, Las Vegas, Nevada. Use code MSCUST for a $150 discount. Prices go up February 11th. Register now.

Reply
hamzashafiq
Kudo Collector
Kudo Collector

Same Week Numbers in Two Months

hamzashafiq_0-1666952900137.png

Hi All,

 

I have created a Week Number column using the following DAX
Week Num= WEEKNUM('DateTable'[Date],2) to calculate the 4 week running average. The problem is that the Week 6 is coming in both Januray and February causing issues in my rolling average calculation. Is there any way we can make the week number unique?

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

Hi @hamzashafiq ,

Please create the measures as below to get the 4 weeks rolling average, you can find the details in the attachment.

Measure = SUM('Table'[Billed Amount])
4 Week Rolling Average = 
VAR _selweek =
    SELECTEDVALUE ( 'DateTable'[Week Num] )
VAR _count =
    IF ( _selweek <= 3, _selweek, 4 )
RETURN
    DIVIDE (
        SUMX (
            FILTER (
                ALLSELECTED ( 'DateTable' ),
                'DateTable'[Week Num] >= _selweek - 3
                    && 'DateTable'[Week Num] <= _selweek
            ),
            [Measure]
        ),
        _count
    )

yingyinr_0-1667205006045.png

If the above one can't help you get the desired result, please provide some sample data in your tables (exclude sensitive data) with Text format and your expected result with backend logic and special examples. It is better if you can share a simplified pbix file. You can refer the following link to upload the file to the community. Thank you.

How to upload PBI in Community

Best Regards

Community Support Team _ Rena
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

2 REPLIES 2
v-yiruan-msft
Community Support
Community Support

Hi @hamzashafiq ,

Please create the measures as below to get the 4 weeks rolling average, you can find the details in the attachment.

Measure = SUM('Table'[Billed Amount])
4 Week Rolling Average = 
VAR _selweek =
    SELECTEDVALUE ( 'DateTable'[Week Num] )
VAR _count =
    IF ( _selweek <= 3, _selweek, 4 )
RETURN
    DIVIDE (
        SUMX (
            FILTER (
                ALLSELECTED ( 'DateTable' ),
                'DateTable'[Week Num] >= _selweek - 3
                    && 'DateTable'[Week Num] <= _selweek
            ),
            [Measure]
        ),
        _count
    )

yingyinr_0-1667205006045.png

If the above one can't help you get the desired result, please provide some sample data in your tables (exclude sensitive data) with Text format and your expected result with backend logic and special examples. It is better if you can share a simplified pbix file. You can refer the following link to upload the file to the community. Thank you.

How to upload PBI in Community

Best Regards

Community Support Team _ Rena
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
amitchandak
Super User
Super User

@hamzashafiq , You can have month week in one two way in your date table

 

WeekDay = WEEKDAY([Date],2) //monday
Start of Week = [Date] -[WeekDay]+1 //monday
Month Week = QUOTIENT(DATEDIFF(Minx(FILTER('Date',[Start Month]=EARLIER([Start Month])),'Date'[Start of Week]),[Date],DAY),7)+1

min week start of month = minx(filter('Date',[Month Year] =earlier([Month Year])),[Week Start date])
week of month = datediff([min week start of month],[date],Week)+1

 

also have month rank

Month Rank = RANKX(all('Date'),'Date'[Month Start Date],,ASC,Dense)

 

This Month Week = CALCULATE(sum('Table'[Qty]), FILTER(ALL('Date'),'Date'[Month Rank]=max('Date'[Month Rank]) && 'Date'[week of month]=max('Date'[week of month]) ))
Last Month Same Week = CALCULATE(sum('Table'[Qty]), FILTER(ALL('Date'),'Date'[Month Rank]=max('Date'[Month Rank])-1 && 'Date'[week of month]=max('Date'[week of month]) ))

 

Full Power BI Video 20 Hours YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount! Prices go up Feb. 11th.

Feb2025 Sticker Challenge

Join our Community Sticker Challenge 2025

If you love stickers, then you will definitely want to check out our Community Sticker Challenge!

Jan25PBI_Carousel

Power BI Monthly Update - January 2025

Check out the January 2025 Power BI update to learn about new features in Reporting, Modeling, and Data Connectivity.

Jan NL Carousel

Fabric Community Update - January 2025

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