Forum Discussion
TomJ54545
4 years agoNew 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.
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]), "#") )
3 Replies
- jdbuchanan71
Super User
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]), "#") )- TomJ54545New Member
Thank you, my week starts on Monday though. How do I change this?
- jdbuchanan71
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]), "#") )