Forum Discussion

Gportari's avatar
Gportari
New Member
10 months ago
Solved

Issue Building a Cash Flow Measure

Hello everyone, I'm currently building an accounting dashboard and I need to create a measure that calculates a running cash flow balance. The challenge is that for the whole year, I have the same i...
  • bhanu_gautam's avatar
    10 months ago

    Gportari Try using

    Use a Running Total Pattern

    1. Calculate the Initial Balance for January

    dax
    Initial_Balance =
    CALCULATE(
    SUM(FT_CONTABEL[CTA_SDOINICIAL]),
    FILTER(
    ALL(DM_TEMPO),
    DM_TEMPO[ANO] = SELECTEDVALUE(DM_TEMPO[ANO]) &&
    DM_TEMPO[MES] = 1
    )
    )

     

    2. Calculate the Cumulative Differential Value up to the Current Month

    dax
    Cumulative_Differential =
    CALCULATE(
    [Valor_Diferenca],
    FILTER(
    ALL(DM_TEMPO),
    DM_TEMPO[ANO] = SELECTEDVALUE(DM_TEMPO[ANO]) &&
    DM_TEMPO[MES] <= MAX(DM_TEMPO[MES])
    )
    )

     

    3. Calculate the Running Balance

    dax
    Running_Balance =
    VAR Initial = [Initial_Balance]
    VAR CumulativeDiff = [Cumulative_Differential]
    RETURN
    IF(
    SELECTEDVALUE(FT_CONTABEL[CTA_NATURALEZA]) = "Acre",
    Initial + CumulativeDiff,
    Initial - CumulativeDiff
    )

     

    Full Example Measure

    dax
    Running_Balance =
    VAR CurrentYear = SELECTEDVALUE(DM_TEMPO[ANO])
    VAR CurrentMonth = MAX(DM_TEMPO[MES])
    VAR InitialBalance =
    CALCULATE(
    SUM(FT_CONTABEL[CTA_SDOINICIAL]),
    FILTER(
    ALL(DM_TEMPO),
    DM_TEMPO[ANO] = CurrentYear &&
    DM_TEMPO[MES] = 1
    )
    )
    VAR CumulativeDiff =
    CALCULATE(
    [Valor_Diferenca],
    FILTER(
    ALL(DM_TEMPO),
    DM_TEMPO[ANO] = CurrentYear &&
    DM_TEMPO[MES] <= CurrentMonth
    )
    )
    RETURN
    IF(
    SELECTEDVALUE(FT_CONTABEL[CTA_NATURALEZA]) = "Acre",
    InitialBalance + CumulativeDiff,
    InitialBalance - CumulativeDiff
    )