Reputation: 1119
I have used the following to get the stating day of the month
multiemp[Day] - WEEKDAY(multiemp[Day],2)
For example if my date us 22 May 2018, after using the above query, got the expected out put.i.e., 20 May 2018
Now I tried to get the month name by using the above query and format function
format(month(multiemp[Day] - WEEKDAY(multiemp[Day],2)),"mmm")
results were not expected, instead of may January is getting populated.
when verify with the following month function expected results arrived .i.e, 5
month(multiemp[Day] - WEEKDAY(multiemp[Day],2)
but only issue in changing the month number to month name
Please find below:
formulas used
weekstartday = multiemp[Day] - WEEKDAY(multiemp[Day],2)
weekstartday_month = month(multiemp[weekstartday])
Month_name = format(multiemp[weekstartday_month],"mmm")
another_ans = format(dateadd(multiemp[Day],-weekday(multiemp[Day],2),day),"mmm")
another_answer_date = dateadd(multiemp[Day],-weekday(multiemp[Day],2),day)
EDIT: Day 2 Modified the datatype of the column to date time/timezone.
after refresh the data didn't change
Found out the solution
Solution 1:
mnname = format(multiemp[weekstartday].[Date],"mmm")
Solution 2:
Month_name = format(date(YEAR(multiemp[weekstartday]),MONTH(multiemp[weekstartday]),day(multiemp[weekstartday])),"mmm")
Thanks in advance
Upvotes: 2
Views: 8085
Reputation: 772
Because FORMAT(...,"MMM")
or FORMAT(...,"MMMM")
takes as an argument a date
types and non numeric
types, try this
format(dateadd(multiemp[Day],-weekday(multiemp[Day],2),day),"MMM")
If you want the starting day of the week as monday, then,
format(dateadd(multiemp[Day],-weekday(multiemp[Day],3),day),"MMM")
EDIT
Verify that date column is date
or date\time
type.
Upvotes: 1
Reputation: 1119
Solution 1:
mnname = format(multiemp[weekstartday].[Date],"mmm")
Solution 2:
Month_name = format(date(YEAR(multiemp[weekstartday]),MONTH(multiemp[weekstartday]),day(multiemp[weekstartday])),"mmm")
Upvotes: 0
Reputation: 98
Format the column instead of repeating the column DAX statement.
Column = FORMAT(*nameOfYourStartOfWeekColumn*,"mmm")
Upvotes: 3