Forum Discussion

MTrullàs's avatar
MTrullàs
Helper III
3 years ago
Solved

Average 7 last inputs

I have a PBI with a metric for calculate inputs.   ENTRADAS =      CALCULATE(     [Coches],         USERELATIONSHIP(         STOCK_EVOLUTION[Fecha_entrada_calculada],'DimDate'[Date]))   ...
  • mariussve1's avatar
    mariussve1
    3 years ago

    Hi again MTrullàs , 

    Not so easy to guess what your [Coches] measure do, but could you please give this a try?

    If we say that [Coches] = SUM ( Table[Column] )

    Then you can try this:

    PROMEDIO_ENTRADAS_7 =
    VAR __LastDate =
        MAX ( STOCK_EVOLUTION[Date] )
    VAR __Last7dates =
        TOPN ( 7, FILTER ( ALL ( STOCK_EVOLUTION[Date] ), STOCK_EVOLUTION[Date] <= __LastDate ), STOCK_EVOLUTION[Date], DESC )
    VAR __Result =
        CALCULATE ( AVERAGEX( STOCK_EVOLUTION, [Entradas] ), __Last7dates )
    RETURN
        __Result
     

    This works for me, so if you cant make it work now, then I can send you an example pbix file.


    Br

    Marius