Format a DD/MM/YYYY date in a measure

I have need to convert an accounting period into a date and it is not formatting properly.
This calculation is to get the first day of the month of the calendar date that the accounting transaction falls in. e.g. 01/mm/yyyy

The DAX I have is:

Transaction Date =
VAR vLyEndMonth = MONTH(MAX(Company[NextYearEnd]))
VAR vLyEndYear = YEAR(MAX(Company[NextYearEnd]))
VAR vTranMM = MONTH(SELECTEDVALUE(NlTransactionSummary[mm]))
VAR vTranYY = YEAR(SELECTEDVALUE(NlTransactionSummary[YY]))
VAR vYeMM = IF(vLyEndMonth + vTranMM > 12, vLyEndMonth - 12, vLyEndMonth)
VAR vYeYY = IF(vLyEndMonth + vTranMM > 12, vLyEndYear - 1, vLyEndYear)
VAR vYeDate = "01" & "/" & vYeMM & "/" & vYeYY
RETURN
vYeDate

The issue is with the month part of the date is not formatting properly. I am getting, for example, -9 for September instead of 09.

Any help greatly appreciated.

1 Like

Hello @PaulBoyes,

I would try to add a Date Column using Power Query and use that in DAX.
Is this possible with your model?

If you liked my solution please give it a thumbs up :+1:.

If I did answer your question please mark my post as a solution :white_check_mark:.

Thank you !

Cristian

You can use FORMAT() to format and/or return parts of a date.
STARTOFMONTH() as the name suggests, returns the first date of the month.

Measure = FORMAT(STARTOFMONTH(ā€˜Transactionsā€™[Date]),ā€œMMā€) //Returns 09 for September.

Measure2 = STARTOFMONTH(ā€˜Transactionsā€™[Date]) //Returns the first date of month for Transaction Date.

Just to build on what @marcster_uk sent , here are some pre-defined time format

ā€œGeneral Dateā€ -
Displays a date and/or time. For example, 3/12/2008 11:07:31 AM. Date display is determined by your applicationā€™s current culture value.

ā€œLong Dateā€ or ā€œMedium Dateā€ -
Displays a date according to your current cultureā€™s long date format. For example, Wednesday, March 12, 2008.

ā€œShort Dateā€ -
Displays a date using your current cultureā€™s short date format. For example, 3/12/2008.

ā€œLong Timeā€ -
Displays a time using your current cultureā€™s long time format; typically includes hours, minutes, seconds. For example, 11:07:31 AM.

ā€œMedium Timeā€ -
Displays a time in 12 hour format. For example, 11:07 AM.

ā€œShort Timeā€ -
Displays a time in 24 hour format. For example, 11:07.

Hi @PaulBoyes, weā€™ve noticed that no response has been received from you since the 23rd of May. We just want to check if you still need further help with this post? In case there wonā€™t be any activity on it in the next few days, weā€™ll be tagging this post as Solved. If you have a follow question or concern related to this topic, please remove the Solution tag first by clicking the three dots beside Reply and then untick the checkbox. Thanks!