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

Grow your Fabric skills and prepare for the DP-600 certification exam by completing the latest Microsoft Fabric challenge.

Reply
SurendraD
Frequent Visitor

Calculating Week number from today to back dated for last 5 Week

Hi All, 

I have a column of dates like this 

Date
3/22/2024
3/21/2024
3/20/2024
3/19/2024
3/18/2024
3/17/2024
3/16/2024
3/15/2024
3/14/2024
3/13/2024
3/12/2024
3/11/2024
3/10/2024
3/9/2024
3/8/2024
3/7/2024
3/6/2024
3/5/2024
3/4/2024
3/3/2024
3/2/2024
3/1/2024
2/29/2024
2/28/2024
2/27/2024
2/26/2024
2/25/2024
2/24/2024
2/23/2024
2/22/2024
2/21/2024
2/20/2024
2/19/2024


I want to calculate the week numbers from today to backward till completed the 5 Weeks and by starts with monday.


Result will be like this 

DateWeek
3/22/2024W1
3/21/2024W1
3/20/2024W1
3/19/2024W1
3/18/2024W1
3/17/2024W2
3/16/2024W2
3/15/2024W2
3/14/2024W2
3/13/2024W2
3/12/2024W2
3/11/2024W2
3/10/2024W3
3/9/2024W3
3/8/2024W3
3/7/2024W3
3/6/2024W3
3/5/2024W3
3/4/2024W3
3/3/2024W4
3/2/2024W4
3/1/2024W4
2/29/2024W4
2/28/2024W4
2/27/2024W4
2/26/2024W4
2/25/2024W5
2/24/2024W5
2/23/2024W5
2/22/2024W5
2/21/2024W5
2/20/2024W5
2/19/2024W5


Can any one please help me to fix this 
@dax @dax @daxdax  @power @SolutionB 
@

2 ACCEPTED SOLUTIONS
lbendlin
Super User
Super User

lbendlin_0-1711225303540.png

Dates =
ADDCOLUMNS (
    CALENDAR ( "2024-01-01", TODAY () ),
    "WeekBack",
        VAR wd =
            WEEKDAY ( TODAY (), 2 )
        VAR wb =
            INT ( DIVIDE ( 14 + TODAY () - wd - [Date], 7 ) )
        RETURN
            IF ( wb < 6, FORMAT ( wb, "\W#" ) )
)

View solution in original post

v-xuxinyi-msft
Community Support
Community Support

Hi @SurendraD 

 

Your solution is great, @lbendlin. It worked like a charm! Here I have another idea in mind, and I would like to share it for reference.

 

You can try this calculated column as follows.

Week Number = 
VAR CurrentWeek = WEEKNUM(MAX([Date]), 2)
VAR DateWeek = WEEKNUM([Date], 2)
RETURN IF((CurrentWeek - DateWeek + 1) <= 5, "W" & CurrentWeek - DateWeek + 1, BLANK())

 

Result:

vxuxinyimsft_0-1711335516982.png

 

When I changed the date to today (3/25/2024):

vxuxinyimsft_1-1711335610257.png

 

Best Regards,
Yulia Xu

 

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

4 REPLIES 4
SurendraD
Frequent Visitor

Thank you for helping me, it's working now 

 

v-xuxinyi-msft
Community Support
Community Support

Hi @SurendraD 

 

Your solution is great, @lbendlin. It worked like a charm! Here I have another idea in mind, and I would like to share it for reference.

 

You can try this calculated column as follows.

Week Number = 
VAR CurrentWeek = WEEKNUM(MAX([Date]), 2)
VAR DateWeek = WEEKNUM([Date], 2)
RETURN IF((CurrentWeek - DateWeek + 1) <= 5, "W" & CurrentWeek - DateWeek + 1, BLANK())

 

Result:

vxuxinyimsft_0-1711335516982.png

 

When I changed the date to today (3/25/2024):

vxuxinyimsft_1-1711335610257.png

 

Best Regards,
Yulia Xu

 

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

Thanks a lot for helping me. it's working now
lbendlin
Super User
Super User

lbendlin_0-1711225303540.png

Dates =
ADDCOLUMNS (
    CALENDAR ( "2024-01-01", TODAY () ),
    "WeekBack",
        VAR wd =
            WEEKDAY ( TODAY (), 2 )
        VAR wb =
            INT ( DIVIDE ( 14 + TODAY () - wd - [Date], 7 ) )
        RETURN
            IF ( wb < 6, FORMAT ( wb, "\W#" ) )
)

Helpful resources

Announcements
RTI Forums Carousel3

New forum boards available in Real-Time Intelligence.

Ask questions in Eventhouse and KQL, Eventstream, and Reflex.

MayPowerBICarousel

Power BI Monthly Update - May 2024

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