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

Power BI is turning 10! Let’s celebrate together with dataviz contests, interactive sessions, and giveaways. Register now.

Reply
ola1996
Helper I
Helper I

YTD or other time intelligence calculation

Hello,

I would like to ask you about specyfic case. My examle 2021-04-26 19_57_57-Power BI Desktop.pngis below. I need to have some YTD calculation across multiple years. It means that I want to see one column "Opening balance" it is not standard functionality OPENINGBALANCE in DAX, it need to be sth more. Opening balance for current month  is closing balance for previous month, and closing balance is YTD calculation but I must have this value from the beggining of the world  till now, so  it is not only current year. 

So I prepare closing balance in DAX like 

 CALCULATE(SUM(BANKACCLEDGENTR[Amount_LCY]),DATESYTD('Calendar'[Date]))
and opening 
CALCULATE([closing balance],PREVIOUSMONTH('Calendar'[Date]))
but how to get correct result in the next year. 
2 REPLIES 2
Anonymous
Not applicable

// You should adjust the names of
// the tables and columns to fit
// your model. These measures work
// correctly for any selection of
// periods, not only months.
 
[Closing Balance] =
var LastVisibleDate = MAX( 'Calendar'[Date] )
var Result =
    CALCULATE(
        SUM( T[Amount] ),
        'Calendar'[Date] <= LastVisibleDate,
        // This last line is not needed
        // if 'Calendar' is a date table
        // that's been marked in the model
        // as a proper date table.
        ALL( 'Calendar' )
    )
return
    Result
    
// Opening Balance

[Opening Balance] =
var FirstVisibleDate = MIN( 'Calendar'[Date] )
var DayBeforeFirstVisibleDate =
    FirstVisibleDate - 1
var Result =
    CALCULATE(
        [Closing Balance],
        'Calendar'[Date] = DayBeforeFirstVisibleDate,
        // Same remark as above applies...
        ALL( 'Calendar' )
    )
return
    Result

Unfortunatelly, I put this formulas in mine .pbix and not working correctly 

Helpful resources

Announcements
June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

Check out the June 2025 Power BI update to learn about new features.

June 2025 community update carousel

Fabric Community Update - June 2025

Find out what's new and trending in the Fabric community.