Don't miss your chance to take the Fabric Data Engineer (DP-600) exam for FREE! Find out how by attending the DP-600 session on April 23rd (pacific time), live or on-demand.
Learn moreNext up in the FabCon + SQLCon recap series: The roadmap for Microsoft SQL and Maximizing Developer experiences in Fabric. All sessions are available on-demand after the live show. 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
If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.
A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.
Experience the highlights from FabCon & SQLCon, available live and on-demand starting April 14th.
| User | Count |
|---|---|
| 47 | |
| 44 | |
| 40 | |
| 20 | |
| 15 |
| User | Count |
|---|---|
| 70 | |
| 68 | |
| 32 | |
| 27 | |
| 25 |