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
EmaVasileva
Helper V
Helper V

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)

sc1.png

 



 

 

 

 

 

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.

 

1 ACCEPTED SOLUTION
mahoneypat
Employee
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




Did I answer your question? Mark my post as a solution! Kudos are also appreciated!

To learn more about Power BI, follow me on Twitter or subscribe on YouTube.


@mahoneypa HoosierBI on YouTube


View solution in original post

1 REPLY 1
mahoneypat
Employee
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




Did I answer your question? Mark my post as a solution! Kudos are also appreciated!

To learn more about Power BI, follow me on Twitter or subscribe on YouTube.


@mahoneypa HoosierBI on YouTube


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.