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

Join the Fabric FabCon Global Hackathon—running virtually through Nov 3. Open to all skill levels. $10,000 in prizes! Register now.

Reply
Wadda7AboUdai
Helper I
Helper I

Calculate stock before 2 years (open balance)

Hi everyone 

I want to sum the stock value before 2 years from the selected year , for example if the selected year is 2024 i want to get stock in 2022 and if the selected year is 2023 I want to get 2021 value and so on

I useed these measures to calculate the selected year and last year 

this yearstock = 

CALCULATE(SUM(GeneralJournalAccountEntryStaging[ACCOUNTINGCURRENCYAMOUNT]),MainAccount[RECID] = 5637144608)

last yearstock = 

CALCULATE(SUM(GeneralJournalAccountEntryStaging[ACCOUNTINGCURRENCYAMOUNT]),PREVIOUSYEAR(CDate[Date]),MainAccount[RECID] = 5637144608)
 
I used PREVIOUSYEAR instad of SAMEPERIODLASTYEAR to get the stock for last year and ignore if there is filter in month 
 
the idea of this is to get the open balance of the stock for this year and last year if there is anther way please share it 
 
 
 
 
 
1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi @Wadda7AboUdai ,

 

Thanks for reaching out! 

I understand you want ignore the filtering of the month. My workaround is to create a separate table contains years. 

I've created a sample for your reference:

Sample data:

vstephenmsft_1-1720604985743.png

 

1.Create a separate year table.

vstephenmsft_0-1720604960293.png

2.Create a measure to return previous data and ignore month filtering.

Previousyear = CALCULATE(SUM('Table'[Value]),FILTER(ALL('Table'),YEAR([Date])=SELECTEDVALUE('Table (2)'[Year])-1))

vstephenmsft_2-1720605140101.png

vstephenmsft_3-1720605167688.png

Thisyear: 

Thisyear=CALCULATE(SUM('Table'[Value]),FILTER(ALL('Table'),YEAR([Date])=SELECTEDVALUE('Table (2)'[Year])))

 

You can check more details by downloading the attachment.

 

Best Regards,

Stephen Tao

 

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

 

View solution in original post

3 REPLIES 3
Wadda7AboUdai
Helper I
Helper I

@Anonymous  thank you for your help 

Anonymous
Not applicable

You’re welcome, @Wadda7AboUdai .

 

Best Regards,

Stephen Tao

Anonymous
Not applicable

Hi @Wadda7AboUdai ,

 

Thanks for reaching out! 

I understand you want ignore the filtering of the month. My workaround is to create a separate table contains years. 

I've created a sample for your reference:

Sample data:

vstephenmsft_1-1720604985743.png

 

1.Create a separate year table.

vstephenmsft_0-1720604960293.png

2.Create a measure to return previous data and ignore month filtering.

Previousyear = CALCULATE(SUM('Table'[Value]),FILTER(ALL('Table'),YEAR([Date])=SELECTEDVALUE('Table (2)'[Year])-1))

vstephenmsft_2-1720605140101.png

vstephenmsft_3-1720605167688.png

Thisyear: 

Thisyear=CALCULATE(SUM('Table'[Value]),FILTER(ALL('Table'),YEAR([Date])=SELECTEDVALUE('Table (2)'[Year])))

 

You can check more details by downloading the attachment.

 

Best Regards,

Stephen Tao

 

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

 

Helpful resources

Announcements
FabCon Global Hackathon Carousel

FabCon Global Hackathon

Join the Fabric FabCon Global Hackathon—running virtually through Nov 3. Open to all skill levels. $10,000 in prizes!

September Power BI Update Carousel

Power BI Monthly Update - September 2025

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

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.