cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
tacobannas Frequent Visitor
Frequent Visitor

Return the 2nd Tuesday of every Month

I am trying to return the 2nd Tuesday of every month. My table has a date for everyday. How can I return this based on the that field. 

1 ACCEPTED SOLUTION

Accepted Solutions
Phil_Seamark Super Contributor
Super Contributor

Re: Return the 2nd Tuesday of every Month

Please try this as a caluculated column

 

Is 2nd Tuesday = 
VAR a = 'Dates'[Date]
VAR y = FILTER(
        ALL(Dates[Date]),
        YEAR('Dates'[Date]) = YEAR(a) && 
        MONTH('Dates'[Date]) = MONTH(a) && 
        DAY([Date]) > 7 && 
        DAY([Date]) < 15 && 
        WEEKDAY([Date],3) = 1)
RETURN MAXX(y,[Date])

To learn more about DAX visit : aka.ms/practicalDAX

Proud to be a Datanaut!

14 REPLIES 14
Super User
Super User

Re: Return the 2nd Tuesday of every Month

Hi @tacobannas,

 

Create these two column:

 

MonthWeekday = MONTH('Calendar'[Date]) & WEEKDAY('Calendar'[Date]) 

weekday_Number = WEEKDAY('Calendar'[Date])

 

Then create this measure:

 

2nd Tuesday =
VAR Date_Max =
    MAX ( 'Calendar'[Date] )
VAR Month_week_Max =
    MAX ( 'Calendar'[MonthWeekday] )
RETURN
    IF (
        CALCULATE (
            COUNT ( 'Calendar'[MonthWeekday] ),
            'Calendar'[Date] <= Date_Max,
            'Calendar'[MonthWeekday] = Month_week_Max
        )
            = 2
            && MAX ( 'Calendar'[weekday_Number] ) = 3,
        "2nd",
        ""
    )

 

Add the measure as a filter on your visuals and you should get the result you need:

dates.png

 

Regards,

MFelix



Did I answer your question? Mark my post as a solution!

Proud to be a Datanaut!




tacobannas Frequent Visitor
Frequent Visitor

Re: Return the 2nd Tuesday of every Month

Thanks, that works as a measure, but I was hoping to return the 2nd Tuesday each month as a date in a column. So for everday of the month in my calendar table I would have a corresponding column with the 2nd Tuesday date. 

Phil_Seamark Super Contributor
Super Contributor

Re: Return the 2nd Tuesday of every Month

Please try this as a calculated column

 

Is 2nd Tuesday = 
VAR x =  IF(WEEKDAY([Date],1) = 3 , DAY([Date]) , 0)
RETURN IF(x > 7 && x < 15 , 1 , 0)

To learn more about DAX visit : aka.ms/practicalDAX

Proud to be a Datanaut!

tacobannas Frequent Visitor
Frequent Visitor

Re: Return the 2nd Tuesday of every Month

That appears to work returning true or false, however I want to return the actual date of the 2nd Tuesday. 

2017-12-05_12-25-54.png

 

 

Phil_Seamark Super Contributor
Super Contributor

Re: Return the 2nd Tuesday of every Month

Hi

 

Please try this

 

Is 2nd Tuesday = 
VAR x =  IF(WEEKDAY([Date],1) = 3 , DAY([Date]) , 0)
RETURN IF(x > 7 && x < 15 , [Date] , blank())

To learn more about DAX visit : aka.ms/practicalDAX

Proud to be a Datanaut!

Highlighted
MarcelBeug Super Contributor
Super Contributor

Re: Return the 2nd Tuesday of every Month

A power Query solution: add a column with formula:

 

= Date.StartOfWeek(#date(Date.Year([Date]),Date.Month([Date]),14),Day.Tuesday)

 

This wil take the 14th of the year/month of the date, and from that date: the start of the week, with Tuesday as the first day of the week. So that must be the 2nd Tuesday in the month.

Specializing in Power Query Formula Language (M)
tacobannas Frequent Visitor
Frequent Visitor

Re: Return the 2nd Tuesday of every Month

This appears to be working, but I need that to be filled into every row value pair, not blank in the instance it is not the 2nd Tuesday. 

Phil_Seamark Super Contributor
Super Contributor

Re: Return the 2nd Tuesday of every Month

So do you mean every row for the month will carry the date that happens to be the 2nd tuesday of each month?


To learn more about DAX visit : aka.ms/practicalDAX

Proud to be a Datanaut!

Phil_Seamark Super Contributor
Super Contributor

Re: Return the 2nd Tuesday of every Month

Please try this as a caluculated column

 

Is 2nd Tuesday = 
VAR a = 'Dates'[Date]
VAR y = FILTER(
        ALL(Dates[Date]),
        YEAR('Dates'[Date]) = YEAR(a) && 
        MONTH('Dates'[Date]) = MONTH(a) && 
        DAY([Date]) > 7 && 
        DAY([Date]) < 15 && 
        WEEKDAY([Date],3) = 1)
RETURN MAXX(y,[Date])

To learn more about DAX visit : aka.ms/practicalDAX

Proud to be a Datanaut!

Helpful resources

Announcements
Community Kudopalooza

Win Power BI Swag with Community Kudopalooza!

Each week, complete activities and be qualified in the drawing for cool Power BI Swag.

Summit North America

Power Platform Summit North America

Register by September 5 to save $200

Virtual Launch Event

Microsoft Business Applications Virtual Launch Event

Watch the event on demand for an in-depth look at the new innovations across Dynamics 365 and the Microsoft Power Platform.

MBAS Gallery

Watch Sessions On Demand!

Continue your learning in our online communities.

Users Online
Currently online: 134 members 1,848 guests
Please welcome our newest community members: