Forum Discussion
Matrix Visual: Row subtotal blank/0 using DAX for custom periods
- 2 years ago
If somebody is getting the same problem, I found a solution to make it works correctly.
I considered that has no value of my CALENDAR TABLE in Subtotal Column, then I got the right result for my subtotal using a new measure.
For example:
TotalCost12Month =
VAR MaxDate = MAX(TBL_CALENDAR_1[DATA])
VAR MaxDate12Month = EOMONTH(MaxDate, -13)
VAR Result =
IF (
HASONEVALUE(TBL_CALENDAR_12[DATA]) &&
MAX(TBL_CALENDAR_12[DATA]) <= MaxDate &&
MIN(TBL_CALENDAR_12[DATA]) > MaxDate12Month,
CALCULATE (
SUMX('_MEASURES_MCHN',[TotalCost]*1),
FILTER (
ALL (
TBL_CALENDAR_1[DATA]
),TBL_CALENDAR_1[DATA] = VALUES (TBL_CALENDAR_12[DATA])
)
),
IF(NOT(HASONEVALUE(TBL_CALENDAR_12[DATA])),[TotalMonthsBefore],BLANK())
)
RETURN ResultIn this scenario I have 2 totals:1) TotalCost: Considering cost per month2) TotalMonthsBefore: Considering the total for your custom period.TotalMonthsBefore =CALCULATE (SUM (FACT_MACHINES[COST]),FILTER (ALL (TBL_CALENDAR_1[DATE]),TBL_CALENDAR_1[DATE] <= MAX(TBL_CALENDAR_1[DATE]) &&TBL_CALENDAR_1[DATE] >= EOMONTH (MAX(TBL_CALENDAR_1[DATE]),-12 <here you can use how many months you want to consider for this measure>)))
If somebody is getting the same problem, I found a solution to make it works correctly.
I considered that has no value of my CALENDAR TABLE in Subtotal Column, then I got the right result for my subtotal using a new measure.
For example:
TotalCost12Month =
VAR MaxDate = MAX(TBL_CALENDAR_1[DATA])
VAR MaxDate12Month = EOMONTH(MaxDate, -13)
VAR Result =
IF (
HASONEVALUE(TBL_CALENDAR_12[DATA]) &&
MAX(TBL_CALENDAR_12[DATA]) <= MaxDate &&
MIN(TBL_CALENDAR_12[DATA]) > MaxDate12Month,
CALCULATE (
SUMX('_MEASURES_MCHN',[TotalCost]*1),
FILTER (
ALL (
TBL_CALENDAR_1[DATA]
),TBL_CALENDAR_1[DATA] = VALUES (TBL_CALENDAR_12[DATA])
)
),
IF(NOT(HASONEVALUE(TBL_CALENDAR_12[DATA])),[TotalMonthsBefore],BLANK())
)
RETURN Result