Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

July 7 - July 17 | Round 2 of the Power BI Dataviz World Championships. Don't miss your chance! Learn more

Reply
rafamorim87
Frequent Visitor

Build a table

Goodnight
Could someone help me, please?

I have to build a table so that the first column is equal to the result of the last column of the previous row.
I tried to create this but I ended up falling into redundancy.

The last column is the result of the value of the first column + second column - third column.

ex:
Beginning of February (= January Balance) + February Credit - February Debit = February Balance

Beginning of March (= February Balance) + March Credit - March Debit = March Balance

So far aheadduvida.jpg

2 REPLIES 2
Jihwan_Kim
Super User
Super User

Hi,

I am not sure how your semantic model looks like, but I tried to create a sample pbix file like below.

Please check the below picture and the attached pbix file whether it suits your requirement.

 

Jihwan_Kim_0-1712631692470.pngJihwan_Kim_1-1712632445164.png

 

WINDOW function (DAX) - DAX | Microsoft Learn

 

Credit: = 
SUM( Data[Credit] )

 

Debit: = 
SUM( Data[Debit] )

 

Opening balance: = 
VAR _t =
    ADDCOLUMNS (
        ALL ( 'Calendar'[Year-Month sort], 'Calendar'[Year-Month] ),
        "@amount", CALCULATE ( SUM ( Data[Amount] ) ),
        "@credit", CALCULATE ( SUM ( Data[Credit] ) ),
        "@debit", CALCULATE ( SUM ( Data[Debit] ) )
    )
VAR _startyearmonth =
    MINX ( FILTER ( _t, [@amount] <> BLANK () ), 'Calendar'[Year-Month sort] )
VAR _startamount =
    CALCULATE (
        SUM ( Data[Amount] ),
        'Calendar'[Year-Month sort] = _startyearmonth
    )
RETURN
    IF (
        SELECTEDVALUE ( 'Calendar'[Year-Month sort] ) = _startyearmonth,
        _startamount,
        SUMX (
            WINDOW ( 1, ABS, -1, REL, _t, ORDERBY ( 'Calendar'[Year-Month sort], ASC ) ),
            [@amount] + [@credit] - [@debit]
        )
    )

 

Closing balance: = 
VAR _t =
    ADDCOLUMNS (
        ALL ( 'Calendar'[Year-Month sort], 'Calendar'[Year-Month] ),
        "@amount", CALCULATE ( SUM ( Data[Amount] ) ),
        "@credit", CALCULATE ( SUM ( Data[Credit] ) ),
        "@debit", CALCULATE ( SUM ( Data[Debit] ) )
    )
RETURN
    SUMX (
        WINDOW ( 1, ABS, 0, REL, _t, ORDERBY ( 'Calendar'[Year-Month sort], ASC ) ),
        [@amount] + [@credit] - [@debit]
    )

 


If this post helps, then please consider accepting it as the solution to help other members find it faster, and give a big thumbs up.


Click here to visit my LinkedIn page

Good morning
Thank you very much for the information.

I placed a photo of my semantic model below.

I had the following doubt:

You suggested doing:

Opening balance: =
VAR_t =
ADDCOLUMNS (
ALL ( 'Calendar'[Year-Month sort], 'Calendar'[Year-Month] ),
"@amount", CALCULATE ( SUM ( Data[Amount] ) ),
"@credit", CALCULATE ( SUM ( Data[Credit] ) ),
"@debit", CALCULATE ( SUM ( Data[Debit] ) )

But I don't have an Amount column in my database, so I can't do (SUM ( Data[Amount] )

In my database , Data[Credit] = Lancamento_Entradas[Valor], Data[Debit] = Lancamento_Saidas[Valor], but

Amount in my model is a measurement (Amount = [Saldo Inicial Planejado]+[Receita Planejada]-[DespesaPlanejada])

How could I do it in this case?

duvida2.jpg

Helpful resources

Announcements
FabCon and SQLCon Barcelona 2026

FabCon & SQLCon – Barcelona 2026

Join us in Barcelona for FabCon and SQLCon, the Fabric, Power BI, SQL, and AI community event. Save €200 with code FABCMTY200.

60 days of Data Days Carousel

Data Days 2026

Join Fabric Data Days 2026: 60 days of free live/on-demand sessions, challenges, study groups, and certification opportunities.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.