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

Join us for an expert-led overview of the tools and concepts you'll need to become a Certified Power BI Data Analyst and pass exam PL-300. 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
Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 community update carousel

Fabric Community Update - June 2025

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