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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
BLAP33
Regular Visitor

Month End Balances per Account and Classification

Hello,

 

I currently have a dataset that auto-updates (sometimes daily) with a "Balance History" by account.  I have multiple columns labeled as "Account", "Class (EG Asset vs Liability)", "Date", and "Balance".  The date column is formatted as xx/xx/xxxx xx:xx:xx AM/PM.  Sometimes the same date will appear with a more recent time stamp.  My overall goal is to only grab rows by month end showing an ending balance per account.

 

I easily took my date/time column and converted it to a decimal date to provide a number based on how "recent" the data is.  I also added a MONTH integer column so I can easily see entries by the month per account.  I now need a formula to only populate a column if it is the latest balance for each account at the last monthly entry so I can chart assets vs liabilities on a month to month.  Example data below:

 

Does anyone know of DAX formatting to help out with this?

 

DateAccountInstitutionBalanceTypeClass
4/2/20 6:23 AMPersonalBROKER$500.00INDIVIDUALAsset
4/2/20 6:23 AMRTH_BLBROKER$505.00ROTH_IRAAsset
4/2/20 6:23 AMHEALTHBROKER$510.00HEALTH_SAVINGS_ACCOUNT_HSAAsset
4/2/20 12:30 AMBANK1BANK1$515.00CHECKINGAsset
4/2/20 12:30 AMVACATIONBANK1$520.00SAVINGSAsset
4/2/20 12:30 AMSAVINGSBANK1$525.00SAVINGSAsset
4/1/20 9:54 PMVISABANK2$530.00OTHERLiability
4/1/20 9:53 PMSAVING2BANK2$535.00SAVINGSAsset
4/1/20 9:53 PMCHECKINGBANK2$540.00CHECKINGAsset
3/31/20 5:32 AMVISABANK2$545.00OTHERLiability
3/31/20 5:32 AMSAVING2BANK2$550.00SAVINGSAsset
3/31/20 5:32 AMCHECKINGBANK2$555.00CHECKINGAsset
3/30/20 12:15 AMVISABANK2$560.00OTHERLiability
3/30/20 12:15 AMCHECKINGBANK2$565.00CHECKINGAsset
3/30/20 12:15 AMSAVING2BANK2$570.00SAVINGSAsset
3/28/20 1:20 AMMORTGAGEBANK2$575.00MORTGAGELiability
3/28/20 1:20 AMVISABANK2$580.00OTHERLiability
3/28/20 1:20 AMCHECKINGBANK2$585.00CHECKINGAsset
3/28/20 1:20 AMSAVING2BANK2$590.00SAVINGSAsset
3/27/20 8:16 PMVISABANK2$595.00OTHERLiability
3/26/20 8:54 PMVISABANK2$600.00OTHERLiability
3/26/20 8:54 PMSAVING2BANK2$605.00SAVINGSAsset
3/26/20 8:54 PMCHECKINGBANK2$610.00CHECKINGAsset
3/25/20 6:05 PMVISABANK2$615.00OTHERLiability
3/25/20 6:05 PMCHECKINGBANK2$620.00CHECKINGAsset
3/25/20 6:05 PMSAVING2BANK2$625.00SAVINGSAsset
3/24/20 5:05 PMVISABANK2$630.00OTHERLiability
3/24/20 5:05 PMCHECKINGBANK2$635.00CHECKINGAsset
3/24/20 5:05 PMSAVING2BANK2$640.00SAVINGSAsset
3/23/20 8:13 PMCHECKINGBANK2$645.00CHECKINGAsset
3/23/20 10:53 AMVISABANK2$650.00OTHERLiability
3/23/20 10:52 AMCHECKINGBANK2$655.00CHECKINGAsset
3/23/20 10:52 AMSAVING2BANK2$660.00SAVINGSAsset
3/21/20 10:32 PMMORTGAGEBANK2$665.00MORTGAGELiability
3/21/20 10:32 PMVISABANK2$670.00OTHERLiability
3/21/20 10:32 PMSAVING2BANK2$675.00SAVINGSAsset
3/21/20 10:32 PMCHECKINGBANK2$680.00CHECKINGAsset
3/20/20 6:02 PMVISABANK2$685.00OTHERLiability
3/20/20 6:02 PMSAVING2BANK2$690.00SAVINGSAsset
3/20/20 6:02 PMCHECKINGBANK2$695.00CHECKINGAsset
3/20/20 6:02 PMCHECKINGBANK2$700.00CHECKINGAsset
3/19/20 6:06 PMCHECKINGBANK2$705.00CHECKINGAsset
1 ACCEPTED SOLUTION

As a follow up, I did figure it out.  It's clunky and I know there is easier syntax; however, my dataset is not huge so it works perfectly.  For reference, here were the steps I took (I am sure some of these can be combined, but I am relativily new to PowerBI):

 

#1) Converted the date column to a decimal via FORMAT (Date Column, "general number")

#2) Added a month integer column so I can see MONTH END type data per acccount via MONTH(Date Column) - Later this year, I will have to add year to this so as data rolls into the next year its not repeating and replacing.

#3) SUMMARIZED the table via  SUMMARIZE(TABLE, TABLE[ACCOUNT], TABLE[MONTH INTEGER], TABLE[CLASS], "Month End Decimal Date", MAX(Table[Decimal Date])) - this took the original table and provided a single line item per MONTH INTEGER per Account per Class, and the key was it found this on the MAX DECIMAL DATE, which would be the latest time stamp for that month integer.  

#4) I used the Month End Decimal Date summarized in step 3 to look up the value of the balance on the previous table (i had to setup a relationship to do this).  I simply did LOOKUPVALUE(Table[End of Month Balance], Table[Account], SUMMARIZEDTABLE[Account], Table[Month Integer], SUMMARIZEDTABLE[Month Integer], Table[Decimal Date], SUMMARIZEDTABLE[Month End Decimal Date]) - this searched my original table for the row containing exactly the same account, month integer, class, month end decimal date (calculated in step #3), and pulled the balance on that time stamp.  

 

This gave my a column with my month end balance for each period, each account, each class to chart.  Thank you to looking into this and providing some insight as PowerBI gives you so many ways to solve your data problem!  Love this software!  

 

Thanks again!

 

View solution in original post

5 REPLIES 5
v-deddai1-msft
Community Support
Community Support

Hi @BLAP33 ,

 

We can use the following measure in visual filter to filter out the latest balance for each account(If it is the latest in the current month, it returns 1, otherwise it returns -1)

 

Measure =

VAR m =

    CALCULATE (

        MAX ( 'Table'[Date] ),

        FILTER (

            ALL ( 'Table' ),

            'Table'[Account] IN DISTINCT ( 'Table'[Account] )

                && MONTH ( 'Table'[Date] ) = MONTH ( MAX ( 'Table'[Date] ) )

                && YEAR ( 'Table'[Date] ) = YEAR ( MAX ( 'Table'[Date] ) )

        )

    )

RETURN

    IF ( m IN DISTINCT ( 'Table'[Date] ), 1, -1 )

 

 

Then we create a table visual (drag the 'Date','Account' and 'Class'column in it ) and add the measure in the visual level filter:

 

Untitled picture4.png

 

Lastly, we can add a month slicer to filter the latest balance for each account in each month:

 

Untitled picture5.png

 

For more details, please refer to the pbix file:https://qiuyunus-my.sharepoint.com/:u:/g/personal/pbipro_qiuyunus_onmicrosoft_com/EW48Hby5COVBk...

 

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

 

Best Regards,

Dedmon Dai

@v-deddai1-msft ,

 

Thank you for taking a look.  I copied the DAX straight from your post, but getting an error on the syntax for 'return' is incorrect.  I am not exactly sure how to access your pbix file as the link was removed.  This looks close to what I am trying to do; however, would this populate a 1 for the last entry for January, February, AND March?  It looks like it would only include the latest month, where I am interested in trying to populate a chart on a monthly basis.  

 

Thank you again!  Appreciate the support as always!

As a follow up, I did figure it out.  It's clunky and I know there is easier syntax; however, my dataset is not huge so it works perfectly.  For reference, here were the steps I took (I am sure some of these can be combined, but I am relativily new to PowerBI):

 

#1) Converted the date column to a decimal via FORMAT (Date Column, "general number")

#2) Added a month integer column so I can see MONTH END type data per acccount via MONTH(Date Column) - Later this year, I will have to add year to this so as data rolls into the next year its not repeating and replacing.

#3) SUMMARIZED the table via  SUMMARIZE(TABLE, TABLE[ACCOUNT], TABLE[MONTH INTEGER], TABLE[CLASS], "Month End Decimal Date", MAX(Table[Decimal Date])) - this took the original table and provided a single line item per MONTH INTEGER per Account per Class, and the key was it found this on the MAX DECIMAL DATE, which would be the latest time stamp for that month integer.  

#4) I used the Month End Decimal Date summarized in step 3 to look up the value of the balance on the previous table (i had to setup a relationship to do this).  I simply did LOOKUPVALUE(Table[End of Month Balance], Table[Account], SUMMARIZEDTABLE[Account], Table[Month Integer], SUMMARIZEDTABLE[Month Integer], Table[Decimal Date], SUMMARIZEDTABLE[Month End Decimal Date]) - this searched my original table for the row containing exactly the same account, month integer, class, month end decimal date (calculated in step #3), and pulled the balance on that time stamp.  

 

This gave my a column with my month end balance for each period, each account, each class to chart.  Thank you to looking into this and providing some insight as PowerBI gives you so many ways to solve your data problem!  Love this software!  

 

Thanks again!

 

CheenuSing
Community Champion
Community Champion

Hi @BLAP33 ,

 

Given the sample data what is the output expected ??

 

Cheers

 

CheenuSing

Did I answer your question? Mark my post as a solution and also give KUDOS !

Proud to be a Datanaut!

@CheenuSing 

 

Thanks for taking a look!  Sorry for the description not being totally there!  There are a couple options, but my end goal would be to have a single column with the month end value/balance of each account.  For example, given the sample data:

 

As March progressed, I would like to have a summary table of the distinct accounts (Visa/Savings2/Checking/Mortgage/etc) with the latest balance populated.  So for TODAY, it would show or populate a table with month end for these accounts as:

3/31/2020  - VISA - $545 - Liability

3/31/2020 - SAVINGS2 - $550 - Asset

3/31/2020 - CHECKING - $555 - Asset

3/28/2020 - Mortgage - $575 - Liability (since no other recent information is provided)

 

the rest of the march dates would be ignored as they are older data for these accounts.  April would just show the date closest to TODAY if possible.  Is this possible?

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

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.