The ultimate Fabric, Power BI, SQL, and AI community-led learning event. Save €200 with code FABCOMM.
Get registeredEnhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.
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:
Solved! Go to Solution.
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:
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.
Hello,
I need help as well, I used the fomula you guys supplied here, but its not working. Please help.
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:
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.
Show your expected result with an example.
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"))
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.
User | Count |
---|---|
78 | |
74 | |
43 | |
32 | |
28 |
User | Count |
---|---|
104 | |
95 | |
51 | |
50 | |
46 |