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
Anonymous
Not applicable

Display Current Week Number 99 starting from 03 December 2017 week starting on Monday to Sunday.

Hello Community,

This project started on 03 December 2017 on Sunday. Week starts from Monday through to Sunday. FYI - Project will go until 2022 and FYE is 30th June.

I want the week number to change dynamically every week to reflect the current week since 03 December 2017 as shown in the screenshot. Also, just below the report title, I want to show reporting period dates for the last week as shown in the screenshot.

I have created a DAX table by copying code from https://www.sqlbi.com/articles/using-generate-and-row-instead-of-addcolumns-in-dax/ but am not sure how to get the Week Number 99? The screenshot shows the data I've got thus far in the Date table.

After achieving this, I need to get the reporting period incorporated dynamically as well.

All the 12 tables have the same date and the data looks similar to the screenshot.

I thought I would use DAX instead of M Language Script because I could re-use this DAX Date table for other reports waiting to be developed on this project.

Can anyone please let me know how to achieve this? Any guidance is greatly appreciated!

Thanks in advance!

Kind regards,

Bhoga

 

 2019-11-04_18-30-29.jpg2019-11-04_18-31-03.jpg2019-11-04_18-31-42.jpg2019-11-04_18-32-06.jpg

 

5 ACCEPTED SOLUTIONS
Anonymous
Not applicable

 

 

CALENDAR 5 = 
VAR BASECALENDAR =
    CALENDAR ( DATE ( 2017, 12, 03 ), DATE ( 2022, 06, 30 ) )
RETURN
    GENERATE (
        BASECALENDAR,
        VAR BASEDATE = [DATE]
        VAR YEARDATE = YEAR ( BASEDATE )
        VAR MONTHNUMBER = MONTH ( BASEDATE )
        VAR MONTHNAME = FORMAT ( BASEDATE, "MMMM" )
        VAR YEARMONTHNAME = FORMAT ( BASEDATE, "MMM YY" )
        VAR YEARMONTHNUMBER = YEARDATE * 12 + MONTHNUMBER -1
        VAR WeekNumber = FORMAT(WEEKNUM(BASEDATE,2),"00")
        RETURN ROW (
            "DAY", BASEDATE,
            "YEAR", YEARDATE,
            "MONTH NUMBER", MONTHNUMBER,
            "MONTH", MONTHNAME,
            "YEAR MONTH NUMBER", YEARMONTHNUMBER,
            "YEAR MONTH", YEARMONTHNAME,
            "Year Week Number",CONCATENATE(YEARDATE,WeekNumber)
        )
    )
Calculated Column = RANKX(FILTER(ALL('CALENDAR 5'[Year Week Number]),RIGHT('CALENDAR 5'[Year Week Number],2)<>"53"),'CALENDAR 5'[Year Week Number],,ASC)-1

 

 

@Anonymous Hi 
Can you please add Year week number in your calendar table (1 st code) and then create a column to get the week number
In case you want to exclude week number 53 for each year use

YearWeekNumber =
RANKX(FILTER(ALL('CALENDAR 5'[Week Number]),RIGHT('CALENDAR 5'[Week Number],2)<>"53"),'CALENDAR 5'[Week Number],,ASC)-1

View solution in original post

Anonymous
Not applicable

Expected = RANKX(FILTER(ALL('CALENDAR 5'[Year Week Number]),RIGHT('CALENDAR 5'[Year Week Number],2)<>"53"),'CALENDAR 5'[Year Week Number],,ASC)-1
CALENDAR 5 = 
VAR BASECALENDAR =
    CALENDAR ( DATE ( 2017, 12, 03 ), DATE ( 2022, 06, 30 ) )
RETURN
    GENERATE (
        BASECALENDAR,
        VAR BASEDATE = [DATE]
        VAR YEARDATE = YEAR ( BASEDATE )
        VAR MONTHNUMBER = MONTH ( BASEDATE )
        VAR MONTHNAME = FORMAT ( BASEDATE, "MMMM" )
        VAR YEARMONTHNAME = FORMAT ( BASEDATE, "MMM YY" )
        VAR YEARMONTHNUMBER = YEARDATE * 12 + MONTHNUMBER -1
        VAR WeekNumber = FORMAT(WEEKNUM(BASEDATE,2),"00")
        RETURN ROW (
            "DAY", BASEDATE,
            "YEAR", YEARDATE,
            "MONTH NUMBER", MONTHNUMBER,
            "MONTH", MONTHNAME,
            "YEAR MONTH NUMBER", YEARMONTHNUMBER,
            "YEAR MONTH", YEARMONTHNAME,
            "Year Week Number",CONCATENATE(YEARDATE,WeekNumber)
        )
    )

View solution in original post

Anonymous
Not applicable

Hi @Anonymous 
If 04 November 2019 to 10 November 2019 is Week number 100 as per your business requirement than above code will do the work for youWeek.png

View solution in original post

Anonymous
Not applicable

Hi @Anonymous Please create following measure to get previous week and previous week date range

PreviousWeek = 
VAR weekNumber = CALCULATE(MAX('CALENDAR 5'[Column]),FILTER('CALENDAR 5','CALENDAR 5'[Date]=TODAY()))
RETURN CONCATENATE("Week",weekNumber-1)
PrevWeekRange = 
VAR _week = CALCULATE(MAX('CALENDAR 5'[Column]),FILTER('CALENDAR 5','CALENDAR 5'[Date]=TODAY()))-1
VAR _start = CALCULATE(MIN('CALENDAR 5'[Date]),FILTER('CALENDAR 5','CALENDAR 5'[Column]=_week))
VAR _end = CALCULATE(MAX('CALENDAR 5'[Date]),FILTER('CALENDAR 5','CALENDAR 5'[Column]=_week))
RETURN CONCATENATE("Reporting Period",CONCATENATE(_start,CONCATENATE("-",_end)))

 

View solution in original post

Anonymous
Not applicable

@Anonymous Please use format function to change the date format

PrevWeekRange = 
VAR _week = CALCULATE(MAX('CALENDAR 5'[Column]),FILTER('CALENDAR 5','CALENDAR 5'[Date]=TODAY()))-1
VAR _start = FORMAT(CALCULATE(MIN('CALENDAR 5'[Date]),FILTER('CALENDAR 5','CALENDAR 5'[Column]=_week)),"dd/MM/yyyy")
VAR _end = FORMAT(CALCULATE(MAX('CALENDAR 5'[Date]),FILTER('CALENDAR 5','CALENDAR 5'[Column]=_week)),"dd/MM/yyyy")
RETURN CONCATENATE("Reporting Period",CONCATENATE(_start,CONCATENATE("-",_end)))

View solution in original post

11 REPLIES 11
Anonymous
Not applicable

Anyone..!


Thanks,

Bhoga

Anonymous
Not applicable

Expected = RANKX(FILTER(ALL('CALENDAR 5'[Year Week Number]),RIGHT('CALENDAR 5'[Year Week Number],2)<>"53"),'CALENDAR 5'[Year Week Number],,ASC)-1
CALENDAR 5 = 
VAR BASECALENDAR =
    CALENDAR ( DATE ( 2017, 12, 03 ), DATE ( 2022, 06, 30 ) )
RETURN
    GENERATE (
        BASECALENDAR,
        VAR BASEDATE = [DATE]
        VAR YEARDATE = YEAR ( BASEDATE )
        VAR MONTHNUMBER = MONTH ( BASEDATE )
        VAR MONTHNAME = FORMAT ( BASEDATE, "MMMM" )
        VAR YEARMONTHNAME = FORMAT ( BASEDATE, "MMM YY" )
        VAR YEARMONTHNUMBER = YEARDATE * 12 + MONTHNUMBER -1
        VAR WeekNumber = FORMAT(WEEKNUM(BASEDATE,2),"00")
        RETURN ROW (
            "DAY", BASEDATE,
            "YEAR", YEARDATE,
            "MONTH NUMBER", MONTHNUMBER,
            "MONTH", MONTHNAME,
            "YEAR MONTH NUMBER", YEARMONTHNUMBER,
            "YEAR MONTH", YEARMONTHNAME,
            "Year Week Number",CONCATENATE(YEARDATE,WeekNumber)
        )
    )
Anonymous
Not applicable

Hi@Anonymous

Your code works.. amazing! thank you so much.

 

Yes, you're right. the week actually starts from 27 November 2017.

Is there any change I need to do into your coding for this to work correctly?

Note: To make it very clear to you.. Current Week from 04 November 2019 to 10 November 2019 is Week 100 as per my Business confirmation.

 

Thanks a million.

 

Kind regards, B

Anonymous
Not applicable

Hi @Anonymous 
If 04 November 2019 to 10 November 2019 is Week number 100 as per your business requirement than above code will do the work for youWeek.png

Anonymous
Not applicable

Hi @Anonymous

Thanks a million for the timely help, greatly appreciated.

Kind regards, B

Anonymous
Not applicable

Hello Experts,

I actually needed to display Last Week Number which is 102 and Last Week Period which is 18/11/2019 to 24/11/2019 at the top of my Power BI Report.

I managed to get the Week Number right 102 but unable to work out my way to the Reporting Week Period!

Attached is the screenshot FYR.

Can you please let me know what changes should I be doing to the 'Week Start & End Date' Measure?

Thank heaps.

Kind regards, B

2019-11-28_13-55-30.jpg2019-11-28_13-56-02.jpg

Anonymous
Not applicable

Hi @Anonymous Please create following measure to get previous week and previous week date range

PreviousWeek = 
VAR weekNumber = CALCULATE(MAX('CALENDAR 5'[Column]),FILTER('CALENDAR 5','CALENDAR 5'[Date]=TODAY()))
RETURN CONCATENATE("Week",weekNumber-1)
PrevWeekRange = 
VAR _week = CALCULATE(MAX('CALENDAR 5'[Column]),FILTER('CALENDAR 5','CALENDAR 5'[Date]=TODAY()))-1
VAR _start = CALCULATE(MIN('CALENDAR 5'[Date]),FILTER('CALENDAR 5','CALENDAR 5'[Column]=_week))
VAR _end = CALCULATE(MAX('CALENDAR 5'[Date]),FILTER('CALENDAR 5','CALENDAR 5'[Column]=_week))
RETURN CONCATENATE("Reporting Period",CONCATENATE(_start,CONCATENATE("-",_end)))

 

Anonymous
Not applicable

Hi@Anonymous 

You're a star mate. Your code is working just perfectly.

One last thing... can I change the format of the Reporting Period dates to read as... DD/MM/YYYY?

Thanks, B

Anonymous
Not applicable

@Anonymous Please use format function to change the date format

PrevWeekRange = 
VAR _week = CALCULATE(MAX('CALENDAR 5'[Column]),FILTER('CALENDAR 5','CALENDAR 5'[Date]=TODAY()))-1
VAR _start = FORMAT(CALCULATE(MIN('CALENDAR 5'[Date]),FILTER('CALENDAR 5','CALENDAR 5'[Column]=_week)),"dd/MM/yyyy")
VAR _end = FORMAT(CALCULATE(MAX('CALENDAR 5'[Date]),FILTER('CALENDAR 5','CALENDAR 5'[Column]=_week)),"dd/MM/yyyy")
RETURN CONCATENATE("Reporting Period",CONCATENATE(_start,CONCATENATE("-",_end)))
Anonymous
Not applicable

Hi @Anonymous

Thank you so much for your prompt response which has been of great help to me.

Your code works just perfect to suit my needs.

Kind regards, B

Anonymous
Not applicable

 

 

CALENDAR 5 = 
VAR BASECALENDAR =
    CALENDAR ( DATE ( 2017, 12, 03 ), DATE ( 2022, 06, 30 ) )
RETURN
    GENERATE (
        BASECALENDAR,
        VAR BASEDATE = [DATE]
        VAR YEARDATE = YEAR ( BASEDATE )
        VAR MONTHNUMBER = MONTH ( BASEDATE )
        VAR MONTHNAME = FORMAT ( BASEDATE, "MMMM" )
        VAR YEARMONTHNAME = FORMAT ( BASEDATE, "MMM YY" )
        VAR YEARMONTHNUMBER = YEARDATE * 12 + MONTHNUMBER -1
        VAR WeekNumber = FORMAT(WEEKNUM(BASEDATE,2),"00")
        RETURN ROW (
            "DAY", BASEDATE,
            "YEAR", YEARDATE,
            "MONTH NUMBER", MONTHNUMBER,
            "MONTH", MONTHNAME,
            "YEAR MONTH NUMBER", YEARMONTHNUMBER,
            "YEAR MONTH", YEARMONTHNAME,
            "Year Week Number",CONCATENATE(YEARDATE,WeekNumber)
        )
    )
Calculated Column = RANKX(FILTER(ALL('CALENDAR 5'[Year Week Number]),RIGHT('CALENDAR 5'[Year Week Number],2)<>"53"),'CALENDAR 5'[Year Week Number],,ASC)-1

 

 

@Anonymous Hi 
Can you please add Year week number in your calendar table (1 st code) and then create a column to get the week number
In case you want to exclude week number 53 for each year use

YearWeekNumber =
RANKX(FILTER(ALL('CALENDAR 5'[Week Number]),RIGHT('CALENDAR 5'[Week Number],2)<>"53"),'CALENDAR 5'[Week Number],,ASC)-1

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.

Top Solution Authors