Forum Discussion
REFERÊNCIA CIRCULAR
Esse é o comportamento esperado > preciso calcular a coluna de SALDO (saldo final)
esses são os valores da atualização:
202411 1,0074846265374
202412 1,00878926844845
202501 1,00523257687855
202502 1,01677428478001
esses são os valores VL EQ. PARTIC
2076,53
2076,53
2162,46
2162,46
Ocorrência matrícula
671422 1
671422 2
671422 3
671422 4
Ocorrência matrícula antes
671422 0
671422 1
671422 2
671422 3
os valores esperados corretos para Saldo Final
2.076,53
4.171,31
6.355,60
8.624,67
eu consigo chegar a esse valor de saldo pela lógica no excel > SE(D3=0;F3;G2*E3 +F3)
Saldo = SE (ocorrência antes = 0 ; VL EQ ; Atualização + Saldo(linha anterior) + VL EQ
(não considerei aqui filtrar antes por matrículas, já que a minha base tem 500 matrículas diferentes, e preciso que essa lógica seja criada respeitando o filtro da mesma matrícula).
tentei replicar essa lógica no power bi > mas não dá certo.
Saldo Anterior =
Saldo Anterior =
VAR LinhaAtual = 'Equacionamento_Query'[Ocorrência]
RETURN
CALCULATE(
MAX('Equacionamento_Query'[Saldo Final]),
FILTER(
'Equacionamento_Query',
'Equacionamento_Query'[Ocorrência] = LinhaAtual - 1
)
)saldo final
Saldo Final = VAR Atualizacao = 'Equacionamento_Query'[AtualizaçãoCota.Cota] VAR Valor = 'Equacionamento_Query'[VL EQ. PARTIC] VAR SaldoAnterior = 'Equacionamento_Query'[Saldo Anterior] RETURN IF( ISBLANK(SaldoAnterior), // Se não houver saldo anterior (primeira linha) Valor, SaldoAnterior * Atualizacao + Valor )
aparece erro na coluna de saldo anterior como referência circular.
Uma dependência circular foi detectada: Equacionamento_Query[Saldo Anterior], Equacionamento_Query[Saldo Final], Equacionamento_Query[Saldo Anterior].
já tentei fazer 500 coisas diferentes e não consigo resolver esse problema. alguém em ajuda, por favor??? eu preciso encontrar alguma maneira de chegar ao meu valor de saldo final informado acima (calculado pelo excel) > seja segregando em 2 colunas (saldo anterior e saldo final), ou calculando direto em 1 coluna (saldo final). não sei o que fazer.
alguém pode corrigir o código e me mandar, por favor?
The standard way to avoid circular references in DAX is to push the calculation down into Power Query.
But you can also consider changing your whole approach. "Ending Balance" is just another word for "Running Total". Rework your formulas (or use quick measures) to calculate the RT instead.
You can use a combination of variables and iterative functions.
You need to calculate the previous balance for each row, filtered by the same matricula.
Saldo Anterior = VAR CurrentMatricula = 'Equacionamento_Query'[Matrícula] VAR CurrentOcorrencia = 'Equacionamento_Query'[Ocorrência] RETURN CALCULATE( MAX('Equacionamento_Query'[Saldo Final]), FILTER( 'Equacionamento_Query', 'Equacionamento_Query'[Matrícula] = CurrentMatricula && 'Equacionamento_Query'[Ocorrência] = CurrentOcorrencia - 1 ) )and another calculated column for the final balance using the previous balance and the current values :
Saldo Final = VAR Atualizacao = 'Equacionamento_Query'[AtualizaçãoCota.Cota] VAR Valor = 'Equacionamento_Query'[VL EQ. PARTIC] VAR SaldoAnterior = 'Equacionamento_Query'[Saldo Anterior] RETURN IF( ISBLANK(SaldoAnterior), Valor, SaldoAnterior * Atualizacao + Valor )
5 Replies
- lbendlinSuper User
The standard way to avoid circular references in DAX is to push the calculation down into Power Query.
But you can also consider changing your whole approach. "Ending Balance" is just another word for "Running Total". Rework your formulas (or use quick measures) to calculate the RT instead.
- AmiraBedhSuper User
You can use a combination of variables and iterative functions.
You need to calculate the previous balance for each row, filtered by the same matricula.
Saldo Anterior = VAR CurrentMatricula = 'Equacionamento_Query'[Matrícula] VAR CurrentOcorrencia = 'Equacionamento_Query'[Ocorrência] RETURN CALCULATE( MAX('Equacionamento_Query'[Saldo Final]), FILTER( 'Equacionamento_Query', 'Equacionamento_Query'[Matrícula] = CurrentMatricula && 'Equacionamento_Query'[Ocorrência] = CurrentOcorrencia - 1 ) )and another calculated column for the final balance using the previous balance and the current values :
Saldo Final = VAR Atualizacao = 'Equacionamento_Query'[AtualizaçãoCota.Cota] VAR Valor = 'Equacionamento_Query'[VL EQ. PARTIC] VAR SaldoAnterior = 'Equacionamento_Query'[Saldo Anterior] RETURN IF( ISBLANK(SaldoAnterior), Valor, SaldoAnterior * Atualizacao + Valor ) - v-nmadadi-msftCommunity Support
Hi belaalva,
May I ask if you have resolved this issue? If so, please mark the helpful reply and accept it as the solution. This will be helpful for other community members who have similar problems to solve it faster.
Thank you.
- v-nmadadi-msftCommunity Support
Hi belaalva,
I wanted to check if you had the opportunity to review the information provided. Please feel free to contact us if you have any further questions. If our responses has addressed your query, please accept it as a solution and give a 'Kudos' so other members can easily find it.
Thank you. - v-nmadadi-msftCommunity Support
Hi belaalva,
As we haven’t heard back from you, we wanted to kindly follow up to check if the solution provided by the community members for the issue worked. If our response addressed, please mark it as Accept as solution and click Yes if you found it helpful.
Thanks and regards