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

Earn a 50% discount on the DP-600 certification exam by completing the Fabric 30 Days to Learn It challenge.

Reply
carolinastalo
Frequent Visitor

Finance Report - Balance sheet - show most recent value

Spoiler
Hello

Hello 

I have a data set with balance sheet values.

My table is like this:

AccountDateBalance End of month
131/01/2019100 
231/01/2019150 
331/01/201960 
128/02/2019150 
328/02/2019120 
231/03/2019500 
130/04/2019200 
430/06/20191000 

 

So I have the balance at the end of month for the accounts. The problem is that not all accounts have balance in all months (for example, for some accounts that did not have any transactions in a specified month). 

 

I need to show something like this, if the time slicer is in june/2019 for example;

 

AccountBalance
1200
2500
3120
41000

 

I need to show the balance for all accounts - for a month in a time slicer.

However, if the account does not have balance in the choosen month, the data does not appear (and the balance sheet report is wrong). Tried many approaches from this forum, but none solved my specific situation

Any help is appreciated! Thanks a lot!

1 ACCEPTED SOLUTION
Anonymous
Not applicable

 

Total Balance =
var __lastVisibleDate = max( 'Calendar'[Date] )
VAR __accountsWithDates =
	calculatetable (
		addcolumns (
		    summarize (
		        Balances,
		        Accounts[AccountId]
		    ),
		    "LastDate",
		    	calculate (
		    		max( Balances[Date] )
		    	)
		),
	    'Calendar'[Date] <= __lastVisibleDate
	)
VAR __accountsWithDatesWithLineage =
    TREATAS (
        __accountsWithDates,
        'Account'[AccountId],
        'Calendar'[Date]
    )
VAR __result =
    CALCULATE (
        sum ( Balances[Balance] ),
        __accountsWithDatesWithLineage
    )
RETURN
	__result

 

This version might be faster than the one I posted before (it returns the same results, of course, but does not use iteration). Bear in mind that you should have a Calendar---a proper Date table---connected to the field Date in Balances. Also, you should only slice and dice by dimensions and the fact table's columns must be hidden. Only measures can be visible in the fact table.

 

Best

D

View solution in original post

9 REPLIES 9
Anonymous
Not applicable

 

Total Balance =
var __lastVisibleDate = max( 'Calendar'[Date] )
VAR __accountsWithDates =
	calculatetable (
		addcolumns (
		    summarize (
		        Balances,
		        Accounts[AccountId]
		    ),
		    "LastDate",
		    	calculate (
		    		max( Balances[Date] )
		    	)
		),
	    'Calendar'[Date] <= __lastVisibleDate
	)
VAR __accountsWithDatesWithLineage =
    TREATAS (
        __accountsWithDates,
        'Account'[AccountId],
        'Calendar'[Date]
    )
VAR __result =
    CALCULATE (
        sum ( Balances[Balance] ),
        __accountsWithDatesWithLineage
    )
RETURN
	__result

 

This version might be faster than the one I posted before (it returns the same results, of course, but does not use iteration). Bear in mind that you should have a Calendar---a proper Date table---connected to the field Date in Balances. Also, you should only slice and dice by dimensions and the fact table's columns must be hidden. Only measures can be visible in the fact table.

 

Best

D

Man, thanks A LOT! It was exactly that. I need to study more about creating variables. I did only basic /intermediate courses about DAX and get a little lost some times.

Anonymous
Not applicable

 

 

// Say you have a Calendar connected to Date
// in Balances (or it could be disconnected as well).
// You also have an Accounts dimension
// that stores the unique Accounts. And you
// have a fact table that stores the Balances
// at the end of the months. As you say, some
// accounts will not have entries for some
// months. Accounts is connected to Balances
// via AccountID (1:*). Slicing can only be
// done via dimensions. All columns in the
// fact must be hidden.

// balance when only 1 account is visible
[_Balance41Account] = // hidden measure
var __oneAccountVisible = hasonevalue( Accounts[AccountID] )
var __maxDate = max( Calendar[Date] )
var __maxDateOfBalance =
	calculate(
		MAX( Balances[Date] ),
		Balances[Date] <= __maxDate,
		ALL( 'Calendar' )
	)
var __balance =
	calculate(
		values( Balances[Balance] ),
		Balances[Date] = __maxDateOfBalance,
		ALL( 'Calendar' )
	)
return
	if( __oneAccountVisible, __balance )
	
// Final measure - visible
[Total Balance] = // works OK for any selection of accounts
	sumx(
		values( Accounts[AccountId] ),
		[_Balance41Account]
	)

 

There is a version that does not use iteration - check my post after this one. The second version should be faster on big tables.

 

Best

D

 

az38
Community Champion
Community Champion

Hi @carolinastalo 

first, create a calendar table with last month days

CalendarTable = FILTER(ADDCOLUMNS(calendar(date(2019,1,1),date(2019,12,31)),"EndMonth",IF(EOMONTH([Date],0) = [Date],TRUE(),FALSE())),[EndMonth]=true())

then add Date field from calendar table to slicer and create a measure in your source table

Measure = 
var _slicerDate = if(ISFILTERED(CalendarTable[Date]),CALCULATE(MAX(CalendarTable[Date])),today())
return
CALCULATE(MAX('Table'[Balance End of month]),'Table'[Date]<=_slicerDate)

do not hesitate to give a kudo to useful posts and mark solutions as solution
LinkedIn

Hello, thanks for the reply.

Forgot to explain something:

In the report I have titles, and need to return subtotals, like this:

 

CURRENT LIABILITIES        (Sum of Values)

Account 1             (Value)

Account 2            (Value)

 

NONCURRENT LIABILITIES     (Sum of Values)

Account 3           (Value)

 

 

I tried this, however if I use MAX, it will also show the MAX value on the subtotals, instead of showing the sum. I need to show not the MAX value of Balance End of month, but just the value. How do I do this?

So at that point, that sounds like a measures total problem. See my post about it here: https://community.powerbi.com/t5/DAX-Commands-and-Tips/Dealing-with-Measure-Totals/td-p/63376

Also, this Quick Measure, Measure Totals, The Final Word should get you what you need:
https://community.powerbi.com/t5/Quick-Measures-Gallery/Measure-Totals-The-Final-Word/m-p/547907


@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...
Anonymous
Not applicable

To get sums you have to iterate the accounts and for each you have to find the balance on the day you want.

And here's the best place to find stuff like this https://www.daxpatterns.com/patterns/

Best
D

Sorry, @carolinastalo 

copy-paste 🙂

Measure = 
var _slicerDate = if(ISFILTERED(CalendarTable[Date]),CALCULATE(MAX(CalendarTable[Date])),today())
var _lastDate = CALCULATE(MAX('Table'[Date]),ALLEXCEPT('Table','Table'[Account]),'Table'[Date]<=_slicerDate)
return
CALCULATE(MAX('Table'[Balance End of month]),'Table'[Date]=_lastDate)

do not hesitate to give a kudo to useful posts and mark solutions as solution
LinkedIn
Greg_Deckler
Super User
Super User

So like the attached?

 

 


@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...

Helpful resources

Announcements
LearnSurvey

Fabric certifications survey

Certification feedback opportunity for the community.

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

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

Top Solution Authors