Find everything you need to get certified on Fabric—skills challenges, live sessions, exam prep, role guidance, and a 50 percent discount on exams.
Get startedEarn a 50% discount on the DP-600 certification exam by completing the Fabric 30 Days to Learn It challenge.
Hi all
I'm working with a measure called 'SalesYTD' and want to display it in a line chart with the months on the X-axis. Here's how I'd like it to behave:
However, I'm encountering an issue. When I select a month, the chart only displays data for that month instead of cumulatively up to that month.
I've considered using variables and the DATESBETWEEN function, but it's leading to errors. Note that 'SalesYTD' is built on a few other measures and utilizes the TOTALYTD function.
Could you assist me in resolving this? Perhaps with some code examples, I might be able to pinpoint what I'm missing.
Thanks in advance!
Hello @Anonymous,
Can you please try this:
1. Define Helper Measures/Variables
Current Year = YEAR(TODAY())
Current Month = MONTH(TODAY())
Selected Year = MAX(Date[Year])
Selected Month = MAX(Date[Month])
2. Modify the SalesYTD Measure
SalesYTD Conditional =
VAR CurrentYear = [Current Year]
VAR CurrentMonth = [Current Month]
VAR SelectedYear = [Selected Year]
VAR SelectedMonth = [Selected Month]
VAR StartDate = DATE(CurrentYear, 1, 1)
VAR EndDate =
IF(
SelectedYear < CurrentYear,
DATE(SelectedYear, 12, 31),
IF(
SelectedYear > CurrentYear,
BLANK(), // Future years
IF(
SelectedMonth > CurrentMonth,
DATE(CurrentYear, CurrentMonth, 1) - 1,
DATE(CurrentYear, SelectedMonth, 1) - 1
)
)
)
RETURN
IF(
ISBLANK(EndDate),
BLANK(),
CALCULATE(
[SalesYTD],
DATESBETWEEN(Date[Date], StartDate, EndDate)
)
)
Should you require any further assistance, please do not hesitate to reach out to me.
User | Count |
---|---|
90 | |
74 | |
67 | |
63 | |
55 |
User | Count |
---|---|
99 | |
88 | |
72 | |
60 | |
59 |