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
rschaudhr
Resolver II
Resolver II

In Calculated Column show the first Wednesday of the current month as default

I have a date column. I want to create another calculated date column where whenever it shows the first Wednesday in the current month and it will say "Default Day" otherwise it will show date from the date column. Is this possible?

 

I was using the following calculated column measure:

 

Default Date =
VAR a = 'SQL Results (3)'[DATE_]
VAR y = FILTER(
ALL('SQL Results (3)'[DATE_]),
YEAR('SQL Results (3)'[DATE_]) = YEAR(a) &&
MONTH('SQL Results (3)'[DATE_]) = MONTH(a) &&
DAY([DATE_]) > 1 &&
DAY([DATE_]) < 7 &&
WEEKDAY([DATE_],3) = 2)
Var Wed = format(MAXX(y,'SQL Results (3)'[DATE_]) = 'SQL Results (3)'[DATE_],true)
Var CurrentMonth = format(MONTH('SQL Results (3)'[DATE_])=Month(NOW()),True)
Return
if(CurrentMonth = "True" || Wed = "True", "Current",'SQL Results (3)'[DATE_])
1 ACCEPTED SOLUTION
v-cazheng-msft
Community Support
Community Support

Hi, @rschaudhr 

You can create a Calculated column as following.

 

Default Date =

VAR cur_day =

    NOW ()

VAR first_wes =

    CALCULATE (

        SELECTEDVALUE ( 'SQL Results (3)'[DATE_] ),

        FILTER (

            ALL ( 'SQL Results (3)'[DATE_] ),

            YEAR ( 'SQL Results (3)'[DATE_] ) = YEAR ( cur_day )

                && MONTH ( 'SQL Results (3)'[DATE_] ) = MONTH ( cur_day )

                && DAY ( [DATE_] ) >= 1

                && DAY ( [DATE_] ) <= 7

                && WEEKDAY ( [DATE_], 3 ) = 2

        )

    )

RETURN

    CONVERT (

        IF (

            'SQL Results (3)'[DATE_] = first_wes,

            "Default Day",

            'SQL Results (3)'[DATE_]

        ),

        STRING

    )

 

The result looks like this:

v-cazheng-msft_0-1613377450452.png

 

Here is the sample.

 

Best Regards,

Caiyun Zheng

 

Is that the answer you're looking for? If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

 

View solution in original post

5 REPLIES 5
Anonymous
Not applicable

Hello,

 

I need help as well, I used the fomula you guys supplied here, but its not working. Please help.

Default Date =
VAR cur_day = NOW ()
VAR first_wes =
    CALCULATE (
        SELECTEDVALUE (NB_CALENDAR[REPORT_DATE]),
    FILTER (
            ALL (NB_CALENDAR[REPORT_DATE]),
            YEAR (NB_CALENDAR[REPORT_DATE]) = YEAR ( cur_day )
                && MONTH (NB_CALENDAR[REPORT_DATE]) = MONTH ( cur_day )
                && DAY ( NB_CALENDAR[REPORT_DATE]) >= 1
                && DAY ( NB_CALENDAR[REPORT_DATE]) <= 7
                && WEEKDAY ( NB_CALENDAR[REPORT_DATE], 3 ) = 2
            )
            )
RETURN
    CONVERT (
        IF (first_wes = SELECTEDVALUE(NB_ACCOUNT_SUMMARY[REPORT_DATE]),
            "Default Day",
            SELECTEDVALUE(NB_CALENDAR[REPORT_DATE])
            ),
        STRING
    )Highlighted is the first Wednesday of the current month and It should show first_wed but it is showing date rather.Highlighted is the first Wednesday of the current month and It should show first_wed but it is showing date rather.
v-cazheng-msft
Community Support
Community Support

Hi, @rschaudhr 

You can create a Calculated column as following.

 

Default Date =

VAR cur_day =

    NOW ()

VAR first_wes =

    CALCULATE (

        SELECTEDVALUE ( 'SQL Results (3)'[DATE_] ),

        FILTER (

            ALL ( 'SQL Results (3)'[DATE_] ),

            YEAR ( 'SQL Results (3)'[DATE_] ) = YEAR ( cur_day )

                && MONTH ( 'SQL Results (3)'[DATE_] ) = MONTH ( cur_day )

                && DAY ( [DATE_] ) >= 1

                && DAY ( [DATE_] ) <= 7

                && WEEKDAY ( [DATE_], 3 ) = 2

        )

    )

RETURN

    CONVERT (

        IF (

            'SQL Results (3)'[DATE_] = first_wes,

            "Default Day",

            'SQL Results (3)'[DATE_]

        ),

        STRING

    )

 

The result looks like this:

v-cazheng-msft_0-1613377450452.png

 

Here is the sample.

 

Best Regards,

Caiyun Zheng

 

Is that the answer you're looking for? If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

 

lbendlin
Super User
Super User

Show your expected result with an example.

lbendlin
Super User
Super User

Default Date = 
var a = YEAR('SQLresults (3)'[DATE_])*100+MONTH('SQLresults (3)'[DATE_])
var m = CALCULATE(min('SQLresults (3)'[DATE_]),'SQLresults (3)',YEAR('SQLresults (3)'[DATE_])*100+MONTH('SQLresults (3)'[DATE_])=a , WEEKDAY('SQLresults (3)'[DATE_],2)=3)
return if('SQLresults (3)'[DATE_]=m,"Default Day",format('SQLresults (3)'[DATE_],"MM/dd/YYYY"))

 

lbendlin_0-1613130765101.png

 

Thank you for providing this dax calculation. Unfortunately, it shows all the first Wednesday of every month. I was looking for first Wednesday for the current month. 

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.