Temporal decomposition

Hello, data lovers! I was studying temporal decomposition in data science and I find the concept very useful for many applications in Power BI. However I know that many small companies can’t afford to pay a Pro license of Power BI to publish reports with R visuals. So, I create a DAX formula to make this possible without R. Check the report below.

These are the formulas used:

Observed data:

Observed = COUNT(chamados[status])  + 0

Trend D7:

Trend = 
VAR D0 = MAX('mCalendário'[Data])
VAR MediaMovel = CALCULATE(
    DIVIDE([Observed], 7, BLANK()),
    DATESINPERIOD ('mCalendário'[Data], D0, - 7, DAY )
)
Return
IF(
    Count('mCalendário'[Data])=0,
    BLANK(),
    IF(
        HASONEVALUE('mCalendário'[Data]),
        MediaMovel, 0
    )
)

Seasonal:

Seasonal = 
VAR DiaDaSemana = SELECTEDVALUE('mCalendário'[DiaSemana])
VAR contexto = FILTER(ALLSELECTED('mCalendário'), [DiaSemana]=DiaDaSemana)
VAR SzComErro = SUMMARIZE(
    ALLSELECTED('mCalendário'),
    [DiaSemana],
    "SazonalidadeSemana", AVERAGEX(
        ALLSELECTED('mCalendário'),
        DIVIDE([Observed],[Trend],BLANK())
    )
)
VAR Erro = CALCULATE(
    AVERAGEX(SzComErro, [SazonalidadeSemana])
)
VAR SAZONALIDADE = CALCULATE(
    DIVIDE(
        AVERAGEX(
            contexto,
            DIVIDE([Observed],[Trend],BLANK())
        ),
        Erro, BLANK()
    )
)
RETURN
SAZONALIDADE

Cyclic + Error or Random:

Random = 
CALCULATE(
    DIVIDE(DIVIDE(
        [Observed],
        [Trend], BLANK()),
        [Seasonal]
    )
)

I hope this could be useful to you! 😃

Tags:

Leave a Reply

Your email address will not be published. Required fields are marked *