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
aktripathi2506
Helper IV
Helper IV

Dax formula to get the wednesday's date based on week selection

Hi,

 

I have a date column for past 5 years, based on which I created year and weeknum slicer.

 

When I select the year and week number from the slicer I want to get the wednesday's date.

 

Please suggest this simple but tricky task.

 

Thanks.

1 ACCEPTED SOLUTION

@aktripathi2506, OK, not sure I 100% understand your scenario, but here is what I came up with:

 

Started with this Enter Data query:

 

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("Vc7BCQAhEEPRXjwvONF11qlF7L8NF0FMIJd3yh8j9Vz+GTzNZytY1US4iiwojMp4GY3hjI/RGSGnJtIgiYBUQDJwOuYC", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type text) meta [Serialized.Text = true]) in type table [Date = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Date", type date}})
in
    #"Changed Type"

Created these three custom columns:

 

Year = YEAR([Date])

WeekNum = WEEKNUM([Date])

WeekDay = WEEKDAY([Date])

Created this measure:

 

Wednesday = IF(HASONEVALUE(Wednesday[WeekNum]),CALCULATE(MAX(Wednesday[Date]),FILTER(Wednesday,Wednesday[WeekDay]=4)),DATE(1900,1,1))

Put the Year and WeekNum slicers on a report page and the "Wednesday" measure as a card visualization and it seemed to work OK.


@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...

View solution in original post

3 REPLIES 3
Greg_Deckler
Super User
Super User

You could use the WEEKDAY function to get the WEEKDAY for each date in a custom column and then filter your visual to just the Wednesday's

 

https://msdn.microsoft.com/en-us/library/ee634550.aspx

 


@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...

HI @Greg_Deckler, I actually wanted to get wednesday's date so I can use it in another formula.

 

I can put only one slicer for week (can not put day slicer), so what I was expecting is when I select week (say week 35) then it should get the wednesday's date for that week and subtract this date from deadline date to fet the remaining week number.

@aktripathi2506, OK, not sure I 100% understand your scenario, but here is what I came up with:

 

Started with this Enter Data query:

 

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("Vc7BCQAhEEPRXjwvONF11qlF7L8NF0FMIJd3yh8j9Vz+GTzNZytY1US4iiwojMp4GY3hjI/RGSGnJtIgiYBUQDJwOuYC", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type text) meta [Serialized.Text = true]) in type table [Date = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Date", type date}})
in
    #"Changed Type"

Created these three custom columns:

 

Year = YEAR([Date])

WeekNum = WEEKNUM([Date])

WeekDay = WEEKDAY([Date])

Created this measure:

 

Wednesday = IF(HASONEVALUE(Wednesday[WeekNum]),CALCULATE(MAX(Wednesday[Date]),FILTER(Wednesday,Wednesday[WeekDay]=4)),DATE(1900,1,1))

Put the Year and WeekNum slicers on a report page and the "Wednesday" measure as a card visualization and it seemed to work OK.


@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...

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.