Forum Discussion
Replace Month Values from Numbers to Names
- 1 year ago
Hi
- Data Model: You have a SalesData table (month, year, sales) and a MonthNames table mapping month (1) to names (January). Ensure a one-to-many relationship between MonthNames[month] and SalesData[month].
- Segmenter: Use MonthNames[MonthName] in the segmenter to show names like "January".
- Fix salesselectedpreviousmonth: If the measure returns 0 or blank, it’s likely due to filter context issues. Check the DAX, e.g.:
salesselectedpreviousmonth =
CALCULATE(
[salesselected],
PREVIOUSMONTH('SalesData'[DateColumn]) -- Requires a date column
)
If no date column exists, calculate manually:
salesselectedpreviousmonth =
VAR CurrentMonth = SELECTEDVALUE('MonthNames'[month])
VAR CurrentYear = SELECTEDVALUE('SalesData'[year])
VAR PrevMonth = IF(CurrentMonth = 1, 12, CurrentMonth - 1)
VAR PrevYear = IF(CurrentMonth = 1, CurrentYear - 1, CurrentYear)
RETURN
CALCULATE(
[salesselected],
'SalesData'[month] = PrevMonth,
'SalesData'[year] = PrevYear
)
- Use a Calendar Table: For better results, create a calendar table with Date, MonthNumber, MonthName, and Year. Relate it to SalesData using a calculated date (e.g., DATE(SalesData[year], SalesData[month], 1)). Then use:
salesselectedpreviousmonth =
CALCULATE(
[salesselected],
PREVIOUSMONTH('Calendar'[Date])
)
Test: Verify that selecting "January" in the segmenter shows correct values for all measures, including salesselectedpreviousmonth.
I wanted to follow up since I haven't heard from you in a while. Have you had a chance to try the suggested solutions?
If your issue is resolved, please consider marking the post as solved. However, if you're still facing challenges, feel free to share the details, and we'll be happy to assist you further.
Looking forward to your response!
Best Regards,
Community Support Team _ C Srikanth.