Forum Discussion
Issue Building a Cash Flow Measure
- 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
)
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
)
Thank you very much, my problem was brilliantly solved!!!