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
jamoroso
Helper I
Helper I

Create a new measure to sum the balance for 1 year prior to the month end date shown.

I have a table that contains month end dates and balances. I am trying to create a calculation that will sum the balance for the month end date of the prior year.  I am using this formula, but the leap year is causing a problem. 

 

Balance Minus 1 Year = CALCULATE(SUM(spDateIssue[Balance]),DATEADD(spDateIssue[Month End Date],-1,YEAR),spDateIssue[Is Last Day Of Month] = "Y")
 
jamoroso_0-1652987697010.png
1 ACCEPTED SOLUTION

Hi @jamoroso ,

 

Thanks for sharing the data. I am not sure whether this is the easiest way, but would this one solve your issue?

Balance using same period Tomstry = 
VAR _currentMonth = MONTH ( MAX ( Table[Month End Date] ) )
VAR _previousYear = YEAR ( MAX ( Table[Month End Date] ) ) - 1
RETURN
CALCULATE ( 
    SUM ( Table[Balance]), 
    REMOVEFILTERS ( Table[Month End Date] ),
    MONTH ( Table[Month End Date] ) = _currentMonth,
    YEAR ( Table[Month End Date] ) = _previousYear
)


Here the result:

tomfox_0-1652990863078.png

 

/Tom
https://www.tackytech.blog/
https://www.instagram.com/tackytechtom/



Did I answer your question➡️ Please, mark my post as a solution ✔️

Also happily accepting Kudos 🙂

Feel free to connect with me on LinkedIn! linkedIn

#proudtobeasuperuser 

View solution in original post

9 REPLIES 9
Anonymous
Not applicable

Hi

 

The problm is in your date in 2020 feb had 19 days and 28 days in 2021.

If you want to erase this, just add a format yearmonth  instaed of date

JamesFr06_0-1652994899006.pngJamesFr06_1-1652994929663.png

 

jamoroso
Helper I
Helper I

Sample data

Process DateMonth End DateIs Last Day Of MonthBalance
202001311/31/2020Y192711525
202001311/31/2020Y1259970
202001311/31/2020Y59902154
202001311/31/2020Y91966623
202001311/31/2020Y130970662
202002292/29/2020Y196948547
202002292/29/2020Y95719878
202002292/29/2020Y131051430
202003313/31/2020Y62478737
202003313/31/2020Y94619356
202003313/31/2020Y131394540
202004304/30/2020Y209600995
202004304/30/2020Y1047838
202004304/30/2020Y69637474
202004304/30/2020Y102866879
202004304/30/2020Y130335372
202005315/31/2020Y107221236
202005315/31/2020Y213551528
202005315/31/2020Y129734649
202006306/30/2020Y220754032
202006306/30/2020Y954008
202006306/30/2020Y107819169
202006306/30/2020Y75255419
202006306/30/2020Y127671475
202007317/31/2020Y115195034
202007317/31/2020Y631396
202007317/31/2020Y77014490
202007317/31/2020Y226001367
202007317/31/2020Y126292139
202008318/31/2020Y116343068
202008318/31/2020Y524547
202008318/31/2020Y230046669
202008318/31/2020Y76031535
202008318/31/2020Y124870937
202009309/30/2020Y119664720
202009309/30/2020Y360662
202009309/30/2020Y75133540
202009309/30/2020Y232674996
202009309/30/2020Y120538223
2020103110/31/2020Y236677751
2020103110/31/2020Y78441424
2020103110/31/2020Y219970
2020103110/31/2020Y126434076
2020103110/31/2020Y118017584
2020113011/30/2020Y126980247
2020113011/30/2020Y78460453
2020113011/30/2020Y88822
2020113011/30/2020Y236974429
2020113011/30/2020Y116588377
2020123112/31/2020Y80927497
2020123112/31/2020Y26263
2020123112/31/2020Y133475995
2020123112/31/2020Y241234046
2020123112/31/2020Y114435771
202101311/31/2021Y79914875
202101311/31/2021Y26329
202101311/31/2021Y136067676
202101311/31/2021Y249111722
202101311/31/2021Y111937984
202102282/28/2021Y252325671
202102282/28/2021Y80861261
202102282/28/2021Y26389
202102282/28/2021Y139580067
202102282/28/2021Y110114488
202103313/31/2021Y17550
202103313/31/2021Y88474912
202103313/31/2021Y149182672
202103313/31/2021Y266396028
202103313/31/2021Y106357416
202104304/30/2021Y271915683
202104304/30/2021Y8229
202104304/30/2021Y91682271
202104304/30/2021Y152282365
202104304/30/2021Y105707734
202105315/31/2021Y151162903
202105315/31/2021Y91438807
202105315/31/2021Y273260827
202105315/31/2021Y104364038
202106306/30/2021Y276002296
202106306/30/2021Y91912580
202106306/30/2021Y150299761
202106306/30/2021Y102722913
202107317/31/2021Y97995686
202107317/31/2021Y100748355
202108318/31/2021Y286424400
202108318/31/2021Y97859893
202108318/31/2021Y153400185
202108318/31/2021Y99344982
202109309/30/2021Y154857831
202109309/30/2021Y96331724
202109309/30/2021Y294254407
202109309/30/2021Y98461533
2021103110/31/2021Y296652899
2021103110/31/2021Y94736494
2021103110/31/2021Y159661438
2021103110/31/2021Y97867538
2021113011/30/2021Y95582473
2021113011/30/2021Y157880092
2021113011/30/2021Y299822025
2021113011/30/2021Y96483406
2021123112/31/2021Y96224363
2021123112/31/2021Y307948796
2021123112/31/2021Y95223107
202201311/31/2022Y144925859
202201311/31/2022Y92839931
202202282/28/2022Y324623608
202202282/28/2022Y148156989
202202282/28/2022Y104584597
202202282/28/2022Y91429390

Hi @jamoroso ,

 

Thanks for sharing the data. I am not sure whether this is the easiest way, but would this one solve your issue?

Balance using same period Tomstry = 
VAR _currentMonth = MONTH ( MAX ( Table[Month End Date] ) )
VAR _previousYear = YEAR ( MAX ( Table[Month End Date] ) ) - 1
RETURN
CALCULATE ( 
    SUM ( Table[Balance]), 
    REMOVEFILTERS ( Table[Month End Date] ),
    MONTH ( Table[Month End Date] ) = _currentMonth,
    YEAR ( Table[Month End Date] ) = _previousYear
)


Here the result:

tomfox_0-1652990863078.png

 

/Tom
https://www.tackytech.blog/
https://www.instagram.com/tackytechtom/



Did I answer your question➡️ Please, mark my post as a solution ✔️

Also happily accepting Kudos 🙂

Feel free to connect with me on LinkedIn! linkedIn

#proudtobeasuperuser 

I have actually the same task to do, these solution is working to get the measure for Febreary balance but it gave a wrong Total (the last period [december] instead of the SUM of all period) as you see in your screenshot !!
I tried using TOTALYTD instead of SUM but still give me the same result !
Any idea please?

Sorry, I am new to Power BI and do not know how to do this. I am using a stored procedure and am doing a right click, select New Measure and type the calculation in. How do I enter all of the above info? Thanks, Janet

Hi @jamoroso ,

 

Don't you worry! We all have been there 🙂

 

Right click on the table or folder you'd like to create your measure in and choose measure:

tomfox_0-1652992513567.png

 

Then there is this white box apeparing where you can paste the code in:

tomfox_1-1652992586341.png

 

You probably need to align the table names and columns so they fit your model.

 

I am not sure what you mean by Stored Procedure since I just know them from SQL Server...

 

Hope this helps!

 

/Tom
https://www.tackytech.blog/
https://www.instagram.com/tackytechtom/

 



Did I answer your question➡️ Please, mark my post as a solution ✔️

Also happily accepting Kudos 🙂

Feel free to connect with me on LinkedIn! linkedIn

#proudtobeasuperuser 

Thank you! This worked. 

 

tackytechtom
Super User
Super User

Hi @jamoroso ,

 

Have you tried to use SAMEPERIODLASTYEAR() instead of DATEADD()?

 

Here a link to MS documentation:

SAMEPERIODLASTYEAR function (DAX) - DAX | Microsoft Docs

 

Let me know if this helps 🙂

 

/Tom
https://www.tackytech.blog/
https://www.instagram.com/tackytechtom/



Did I answer your question➡️ Please, mark my post as a solution ✔️

Also happily accepting Kudos 🙂

Feel free to connect with me on LinkedIn! linkedIn

#proudtobeasuperuser 

Yes, I tried this and I get the same issue with Feb. 

 

Balance using same period = CALCULATE(SUM(spDateIssue[Balance]),SAMEPERIODLASTYEAR(spDateIssue[Month End Date]),spDateIssue[Is Last Day Of Month] = "Y")

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.