Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
5 years ago
Solved

Current week based on custom field

Hi all,

I need some help with a calculated column. I have the following data:

DateWeekCustom weekValue
June 1725245
June 1825246
June 1925245
June 2026248
June 2126249
June 22262412
June 2326242
June 2426253
June 2526255
June 2626255
June 2727256
June 2827257
June 2927253
June 3027254
July 127265
July 227263
July 327263
July 428268
July 528269
July 628269
July 728261
July 828272



All data is for 2021 and new dates will be added in future. The week field - the week number starts from Sunday.

My custom week starts from Thursday. I need a Yes/No calculated column which I can use as a Slicer to return Yes/No for "Is current week"? (based on my custom week)

 



 

 

 

 

 

So the desired result should be; If I select from "Is current week"- 'Yes', a bar chart should return all values by dates for the current custom week (in this example 25 week- June 24 until June 30). If today is July 1st and the Current week is Yes - there should be values only for July 1st, and etc.

Thank you.

 

  • You can add a DAX column using a pattern like this

     

    CurrentWeek =
    VAR todaydate =
        TODAY ()
    VAR thisdate = 'Date'[Date]
    VAR todayThursday =
        IF (
            WEEKDAY ( todaydate ) >= 5,
            todaydate - WEEKDAY ( todaydate ) + 5,
            todaydate - WEEKDAY ( todaydate ) - 2
        )
    VAR thisThursday =
        IF (
            WEEKDAY ( thisdate ) >= 5,
            thisdate - WEEKDAY ( thisdate ) + 5,
            thisdate - WEEKDAY ( thisdate ) - 2
        )
    RETURN
        IF ( todayThursday = thisThursday"Y""N" )

     
    FYI that this would be easier in the query with M.  Also, please take a look at this article with some Date tables you could adapt, and then set your filter/slicer to Weeks from today as 0 (instead of "Y").
     
    Pat

1 Reply

  • mahoneypat's avatar
    mahoneypat
    Icon for Microsoft Employee rankMicrosoft Employee

    You can add a DAX column using a pattern like this

     

    CurrentWeek =
    VAR todaydate =
        TODAY ()
    VAR thisdate = 'Date'[Date]
    VAR todayThursday =
        IF (
            WEEKDAY ( todaydate ) >= 5,
            todaydate - WEEKDAY ( todaydate ) + 5,
            todaydate - WEEKDAY ( todaydate ) - 2
        )
    VAR thisThursday =
        IF (
            WEEKDAY ( thisdate ) >= 5,
            thisdate - WEEKDAY ( thisdate ) + 5,
            thisdate - WEEKDAY ( thisdate ) - 2
        )
    RETURN
        IF ( todayThursday = thisThursday"Y""N" )

     
    FYI that this would be easier in the query with M.  Also, please take a look at this article with some Date tables you could adapt, and then set your filter/slicer to Weeks from today as 0 (instead of "Y").
     
    Pat