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

Join us at FabCon Atlanta from March 16 - 20, 2026, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM. Register now.

Reply
Syndicate_Admin
Administrator
Administrator

Convert format week to date format

Hello, good evening.

I would like to ask for help, I need to pass the next column week by date.

Patrozork_0-1670814568559.png

However, when using the following DAX, I have problems with weeks 1 to 9, since they only have 1 digit, try to add the 0 before, replacing for example the 1 by the 01, however, I change all the values where a 1 appears, example the 11 becomes a 101 or 110.

WeekStart = 
MINX(
    FILTER (
        CALENDAR (
            DATE ( LEFT ( [YEARWEAK], 4 ), 1, 1 ),
            DATE ( LEFT ( [YEARWEAK], 4 ), 12, 31 )
        ),
        WEEKNUM ( [Date], 1 ) = VALUE ( RIGHT ( [YEARWEAK], 2 ) )
    ),
    [Date]
)

Patrozork_1-1670814593969.png

The above is as follows, where weeks 1 to 9, are incorrect.

Thanks for reading!

1 ACCEPTED SOLUTION

aha, RETURN is missing

 

WeekStart =

VAR _len = LEN([YEARWEAK])
VAR _value = IF(_len=6, 2, 1)
RETURN
MINX(
    FILTER (
        CALENDAR (
            DATE ( LEFT ( [YEARWEAK], 4 ), 1, 1 ),
            DATE ( LEFT ( [YEARWEAK], 4 ), 12, 31 )
        ),
        WEEKNUM ( [Date], 1 ) = VALUE ( RIGHT ( [YEARWEAK], _value ) )
    ),
    [Date]
)

View solution in original post

4 REPLIES 4
FreemanZ
Super User
Super User

try to add a LEN condition, like this:
 
WeekStart =
VAR _len = LEN([YEARWEAK])
VAR _value = IF(_len=6, 2, 1)
MINX(
    FILTER (
        CALENDAR (
            DATE ( LEFT ( [YEARWEAK], 4 ), 1, 1 ),
            DATE ( LEFT ( [YEARWEAK], 4 ), 12, 31 )
        ),
        WEEKNUM ( [Date], 1 ) = VALUE ( RIGHT ( [YEARWEAK], _value ) )
    ),
    [Date]
)

It throws me the following error, you know why it could be?

Patrozork_0-1670817664180.png

aha, RETURN is missing

 

WeekStart =

VAR _len = LEN([YEARWEAK])
VAR _value = IF(_len=6, 2, 1)
RETURN
MINX(
    FILTER (
        CALENDAR (
            DATE ( LEFT ( [YEARWEAK], 4 ), 1, 1 ),
            DATE ( LEFT ( [YEARWEAK], 4 ), 12, 31 )
        ),
        WEEKNUM ( [Date], 1 ) = VALUE ( RIGHT ( [YEARWEAK], _value ) )
    ),
    [Date]
)

Thanks a lot!! Greetings and good evening

Helpful resources

Announcements
FabCon Global Hackathon Carousel

FabCon Global Hackathon

Join the Fabric FabCon Global Hackathon—running virtually through Nov 3. Open to all skill levels. $10,000 in prizes!

October Power BI Update Carousel

Power BI Monthly Update - October 2025

Check out the October 2025 Power BI update to learn about new features.

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.