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
Prabhu11
Frequent Visitor

Ignore zeros while calculating closing stock value

Hi Community,

 

I'm facing a challenge in calculating the last closing value, kindly help

 

The following table represents the data model I'm using, 

 

my requirement is to return a non-zero value from the last month of the time period selected from the slicer,

For example, if a user selects a date range from 01 Jan 2022 to 31 March 2022.

 

Expected Closing Stock output = 130

Expected Closing Stock target = 110

 

DatesClosing stock  actualTarget
01-01-221000
31-01-22090
01-02-22900
28-02-220100
01-03-221300
31-03-220110

 

I tried following formulas

1.  CALCULATE SUM (Closing stock actual) ), LASTDATE(Date'[dates]')

         Here is the problem I faced, PBI returned 0 as result for actual.  Target working fine because it consists of value in the last date.

 

2. CLOSINGBALANCEMONTH SUM(Closing stock),    Date'[dates]')
       Here also the same issue, PBI returned 0 as the result for actual. 
 
Kindly help,
Thank You
1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi @Prabhu11 ,

 

Please try:

Measure = 
VAR _MAX_DATE=CALCULATE(MAX('Table'[Dates]),'Table'[Dates]<=MAX('Table'[Dates])&&'Table'[Closing stock  actual]<>0)
VAR _VALUE = CALCULATE(MAX('Table'[Closing stock  actual]),'Table'[Dates]=_MAX_DATE)
RETURN
_VALUE

vcgaomsft_0-1668589693432.png

Best Regards,
Gao

Community Support Team

 

If there is any post helps, then please consider Accept it as the solution  to help the other members find it more quickly. If I misunderstand your needs or you still have problems on it, please feel free to let us know. Thanks a lot!

How to get your questions answered quickly -- How to provide sample data

View solution in original post

3 REPLIES 3
Prabhu11
Frequent Visitor

Hi Bifinity,

 

Thanks for the response,

I tried the solution you suggested but that did not work as I expected. Kindly check the attached screenshot.

 

Expected Output = 130 (even if I select the date range up to 31st March 2022)

 

Capture.PNG

 

Regards,

Prabhu

Anonymous
Not applicable

Hi @Prabhu11 ,

 

Please try:

Measure = 
VAR _MAX_DATE=CALCULATE(MAX('Table'[Dates]),'Table'[Dates]<=MAX('Table'[Dates])&&'Table'[Closing stock  actual]<>0)
VAR _VALUE = CALCULATE(MAX('Table'[Closing stock  actual]),'Table'[Dates]=_MAX_DATE)
RETURN
_VALUE

vcgaomsft_0-1668589693432.png

Best Regards,
Gao

Community Support Team

 

If there is any post helps, then please consider Accept it as the solution  to help the other members find it more quickly. If I misunderstand your needs or you still have problems on it, please feel free to let us know. Thanks a lot!

How to get your questions answered quickly -- How to provide sample data

Bifinity_75
Solution Sage
Solution Sage

Hi @Prabhu11 try with this measure:

Mesure = 
CALCULATE(max('Table'[Closing Stock] ), 
    filter('Table','Table'[Closing Stock]<>0),'Table'[Date]<=max('Table'[Date]))

The result:

Bifinity_75_0-1667497909504.png

Best regards

Helpful resources

Announcements
July PBI25 Carousel

Power BI Monthly Update - July 2025

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

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.