Forum Discussion
FORMAT() returns wrong month
- 6 years ago
Hello IanCockcroft
You don't actually need to call the month for formatting your date the way want, you can just use
dispPevMnthScenario = FORMAT ( LASTDATE ( calender[PK_Date] ) , "m/d/yyyy-mmm" )
The reason you are seeing Jan in your string is because you used MONTH in your formula.
The MONTH of 2/28/2019 is 2
PowerBI sees numbers as a date so when you format 2 as MMM it converts 2 to a date of 1/1/1900 then gives you the mmm of that date which is Jan. Here is an image showing both:
Hello IanCockcroft
You don't actually need to call the month for formatting your date the way want, you can just use
dispPevMnthScenario = FORMAT ( LASTDATE ( calender[PK_Date] ) , "m/d/yyyy-mmm" )
The reason you are seeing Jan in your string is because you used MONTH in your formula.
The MONTH of 2/28/2019 is 2
PowerBI sees numbers as a date so when you format 2 as MMM it converts 2 to a date of 1/1/1900 then gives you the mmm of that date which is Jan. Here is an image showing both:
- IanCockcroft6 years agoPost Patron
Thanks jdbuchanan71.
The final measure code is
dispPrevMnthScenario =var scenario1 = SELECTEDVALUE('Scenario type'[Scenario])var PrevYearMonth = FORMAT ( DATEADD(FIRSTDATE(Calender[PK_Date]), -1, MONTH) , "yyyy") &"-"&FORMAT ( DATEADD(FIRSTDATE(Calender[PK_Date]), -1, MONTH) , "mmm")returnPrevYearMonth & " "& scenario1This is used to change column headers depending on selections. budgets, actuals, scenariosthanks a milIan - kymramosrpo1 year agoAdvocate V
💯
LASTDATE did the trick - thank you so much!