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

Don't miss out! 2025 Microsoft Fabric Community Conference, March 31 - April 2, Las Vegas, Nevada. Use code MSCUST for a $150 discount. Prices go up February 11th. 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
v-stephen-msft
Community Support
Community Support

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

@v-stephen-msft  thank you for your help 

You’re welcome, @Wadda7AboUdai .

 

Best Regards,

Stephen Tao

v-stephen-msft
Community Support
Community Support

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
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

December 2024

A Year in Review - December 2024

Find out what content was popular in the Fabric community during 2024.