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

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.

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
July 2025 community update carousel

Fabric Community Update - July 2025

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

July PBI25 Carousel

Power BI Monthly Update - July 2025

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