Forum Discussion
Displaying historical data
- 3 years ago
Anonymous,
Try this solution.
1. Create a calculated column in FactTable. Since the current row is unaffected by the date slicer, we can create a calculated column which identifies the current row (max date) for each combination of plant/division/name. This is more performant than a measure since it is calculated only once when the model refreshes, and it's reusable throughout the model.
Current Row = VAR vPlant = FactTable[plant] VAR vDivision = FactTable[division] VAR vName = FactTable[name] VAR vTable = FILTER ( FactTable, FactTable[plant] = vPlant && FactTable[division] = vDivision && FactTable[name] = vName ) VAR vMaxDate = MAXX ( vTable, FactTable[start_date] ) VAR vResult = IF ( FactTable[plant] = vPlant && FactTable[division] = vDivision && FactTable[name] = vName && FactTable[start_date] = vMaxDate, 1 ) RETURN vResultYou can now use the filter "Current Row = 1" in measures and filters.
2. Create a date table "DateSlicer" with no relationships. You can do this in Power Query or DAX.
3. Create measure:
Manager Count = VAR vDateSlicer = MAX ( DateSlicer[Date] ) VAR vResult = CALCULATE ( COUNTROWS ( FactTable ), FactTable[start_date] <= vDateSlicer, FactTable[job_title] = "Manager", FactTable[Current Row] = 1 ) RETURN vResult4. Create a slicer using DateSlicer[Date] and add the measure to a visual:
Anonymous,
Try this solution.
1. Create a calculated column in FactTable. Since the current row is unaffected by the date slicer, we can create a calculated column which identifies the current row (max date) for each combination of plant/division/name. This is more performant than a measure since it is calculated only once when the model refreshes, and it's reusable throughout the model.
Current Row =
VAR vPlant = FactTable[plant]
VAR vDivision = FactTable[division]
VAR vName = FactTable[name]
VAR vTable =
FILTER (
FactTable,
FactTable[plant] = vPlant
&& FactTable[division] = vDivision
&& FactTable[name] = vName
)
VAR vMaxDate =
MAXX ( vTable, FactTable[start_date] )
VAR vResult =
IF (
FactTable[plant] = vPlant
&& FactTable[division] = vDivision
&& FactTable[name] = vName
&& FactTable[start_date] = vMaxDate,
1
)
RETURN
vResult
You can now use the filter "Current Row = 1" in measures and filters.
2. Create a date table "DateSlicer" with no relationships. You can do this in Power Query or DAX.
3. Create measure:
Manager Count =
VAR vDateSlicer =
MAX ( DateSlicer[Date] )
VAR vResult =
CALCULATE (
COUNTROWS ( FactTable ),
FactTable[start_date] <= vDateSlicer,
FactTable[job_title] = "Manager",
FactTable[Current Row] = 1
)
RETURN
vResult
4. Create a slicer using DateSlicer[Date] and add the measure to a visual: