Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
3 years ago
Solved

Displaying historical data

Hello everyone.   I have very interesting topic and I can't figure out how to handle this task. I will be very grateful to hear the proposals of some experts as I'm a totally newbie in the PowerBI ...
  • DataInsights's avatar
    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
        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: