Power BI is turning 10, and we’re marking the occasion with a special community challenge. Use your creativity to tell a story, uncover trends, or highlight something unexpected.
Get startedJoin us for an expert-led overview of the tools and concepts you'll need to become a Certified Power BI Data Analyst and pass exam PL-300. Register now.
Input:
import pandas as pd
data = {
'Mes': list(range(1, 7)),
'Entrada': [892.78, 322.32, 557.25, 1034.96, 1641.06, 544.83],
'Saida': [997.81, 313.25, 734.94, 921.74, 859.57, 1142.17]
}
df = pd.DataFrame(data)
# Calculando o saldo
saldo = 0
saldo_list = []
for entrada, saida in zip(df['Entrada'], df['Saida']):
saldo = max(0, saldo + entrada - saida)
saldo_list.append(saldo)
df['Saldo'] = saldo_list
print(df)
output:
Mes | Entrada | Saida | Saldo |
1 | 892.78 | 997.81 | 0.00 |
2 | 322.32 | 313.25 | 9.07 |
3 | 557.25 | 734.94 | 0.00 |
4 | 1034.96 | 921.74 | 113.22 |
5 | 1641.06 | 859.57 | 894.71 |
6 | 544.83 | 1142.17 | 297.37 |
Hi @VilmarSch ,
Based on my testing, please try the following methods:
1.Create the simple table.
2.Create the measure to calculate saldo.
Saldo =
VAR sal = 0
VAR entra = CALCULATE(SUMX('Table', 'Table'[Entrada]))
VAR sasi = CALCULATE(SUMX('Table', 'Table'[Saida]))
RETURN
MAX(0, 0 + entra - sasi)
3.Drag the measure into the table visual, the result is shown below.
Best Regards,
Wisdom Wu
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
@Anonymousthanks for the answer, but it didn't give the expected result. I believe it is something more complex.
Hi @VilmarSch ,
May be you can try to use power query.
Solved: Do Not Consider If Accumulated Value Is Negative P... - Microsoft Fabric Community
Best Regardsd,
Wisdom Wu
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
@AnonymousI saw this topic, but I really needed to do it in DAX
This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.
Check out the June 2025 Power BI update to learn about new features.
User | Count |
---|---|
72 | |
71 | |
57 | |
38 | |
36 |
User | Count |
---|---|
81 | |
67 | |
61 | |
46 | |
45 |