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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
TomJ54545
New Member

Write current and previous week in a date table

Hi, 

 

I have a date table where I have 2 columns, 1 for previous week and the same for the current week, where I get the true/false values. The DAX for the columns is as follows: 

 

Previous Week = 
IF ( ( WEEKNUM ( NOW (), 2 ) - 1 ) = Calendar[Week Number], TRUE, FALSE )

Current Week = 
IF ( ( WEEKNUM ( NOW (), 2 ) - 0 ) = 'Calendar'[Week Number], TRUE, FALSE )

 

This works fine but I would however like that I have just 1 column, where I have the text "Current Week" and "Previous Week" for the appropriate weeks and then the week numbers in the rest of the column. I'm unsure how to do this though. 

Could someone please advise me? 

 

Thanks. 

1 ACCEPTED SOLUTION
jdbuchanan71
Super User
Super User

Like this.

Week = 
VAR _DateWeek = [Date] - WEEKDAY ( [Date], 2 )
VAR _Today = TODAY()
VAR _ThisWeek = _Today - WEEKDAY( _Today, 2 )
VAR _LastWeek = _Today - WEEKDAY( _Today, 2 ) - 7
RETURN
SWITCH(
    TRUE(),
    _DateWeek = _ThisWeek, "Current Week",
    _DateWeek = _LastWeek, "Last Week",
    FORMAT(  WEEKNUM([Date]), "#")
)

View solution in original post

3 REPLIES 3
jdbuchanan71
Super User
Super User

Like this.

Week = 
VAR _DateWeek = [Date] - WEEKDAY ( [Date], 2 )
VAR _Today = TODAY()
VAR _ThisWeek = _Today - WEEKDAY( _Today, 2 )
VAR _LastWeek = _Today - WEEKDAY( _Today, 2 ) - 7
RETURN
SWITCH(
    TRUE(),
    _DateWeek = _ThisWeek, "Current Week",
    _DateWeek = _LastWeek, "Last Week",
    FORMAT(  WEEKNUM([Date]), "#")
)
jdbuchanan71
Super User
Super User

@TomJ54545 

I think this will do what you are looking for.

 

Week Column = 
VAR _DateWeek = [Date] - WEEKDAY ( [Date] )
VAR _Today = TODAY()
VAR _ThisWeek = _Today - WEEKDAY( _Today )
VAR _LastWeek = _Today - WEEKDAY( _Today ) - 7
RETURN
SWITCH(
    TRUE(),
    _DateWeek = _ThisWeek, "Current Week",
    _DateWeek = _LastWeek, "Last Week",
    FORMAT(  WEEKNUM([Date]), "#")
)

 

2022-03-19_16-29-50.jpg

Thank you, my week starts on Monday though. How do I change this? 

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

December 2025 Power BI Update Carousel

Power BI Monthly Update - December 2025

Check out the December 2025 Power BI Holiday Recap!

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.