I am attempting to create a column chart where the x-axis uses the month and year from a Date table. My Date table is generated using this code:
Date =
VAR __startDate = DATE(YEAR(TODAY())-4, MONTH(TODAY())+1, 1)
VAR __endDate = EOMONTH(TODAY(), 0)
VAR __dates = CALENDAR ( __startDate, __endDate )
RETURN
ADDCOLUMNS (
__dates,
"Year", YEAR ( [Date] ),
"Fiscal Year", IF(MONTH([Date])<=6, YEAR([Date]), YEAR([Date])+1),
"Month Number", MONTH ( [Date] ),
"Month Name", FORMAT ( [Date], "MMMM" ),
"Month", FORMAT( [Date], "MMM YYYY" ),
"Month Sort", FORMAT( [Date], "YYYY-MM" ),
"Quarter", "Q" & FORMAT( [Date], "Q YYYY" ),
"Quarter Sort", FORMAT ( [Date], "YYYY-Q" )
)
This creates the date range ending the last day of the current month back to the start of the next month 4 years prior. For example, as of today (9/5/2024), __startDate = 10/1/2020 and __endDate = 9/30/2024. This is working as expected.
When I use these dates in my column chart, data in the columns are being displayed correctly i.e. data is displayed for October 2020 through September 2024. However, the remaining months in 2020 and 2024 are being displayed, as well (see image below.)
Blank Months at Start of 2020 :
Blank Months at End of 2024 :
On the x-axis I’m using the month and year from the date hierarchy. On the y-axis, I’m displaying the following measures:
Num Int Rx Accruals =
VAR num_accrual =
CALCULATE(
COUNT(Demographics[On Study Date]),
USERELATIONSHIP('Date'[Date], Demographics[On Study Date]),
'Master Protocol List'[DT4 Pcl Type]="Interventional Treatment"
)
VAR result = IF(ISBLANK(num_accrual), 0, num_accrual)
RETURN result
Num Int Non-Rx Accruals =
VAR num_accrual =
CALCULATE(
COUNT(Demographics[On Study Date]),
USERELATIONSHIP('Date'[Date], Demographics[On Study Date]),
'Master Protocol List'[DT4 Pcl Type]="Interventional Non-Treatment"
)
VAR result = IF(ISBLANK(num_accrual), 0, num_accrual)
RETURN result
Num Obs Accruals =
VAR num_accrual =
CALCULATE(
COUNT(Demographics[On Study Date]),
USERELATIONSHIP('Date'[Date], Demographics[On Study Date]),
'Master Protocol List'[DT4 Pcl Type]="Observational"
)
VAR result = IF(ISBLANK(num_accrual), 0, num_accrual)
RETURN result
Num AncCorr Accruals =
VAR num_accrual =
CALCULATE(
COUNT(Demographics[On Study Date]),
USERELATIONSHIP('Date'[Date], Demographics[On Study Date]),
'Master Protocol List'[DT4 Pcl Type]="Ancillary or Correlative"
)
VAR result = IF(ISBLANK(num_accrual), 0, num_accrual)
RETURN result
There is a disabled relationship between Date[Date] and Demographics[Date] which I am enabling in these measures. The earliest date in Demographics[Data] is 7/1/2020, and the latest date will never be a future date.
The measures are calculating the correct values, which are being displayed in each column correctly, but I don’t want months prior to and after the date range in the Date table to be present in the chart.
2