Don't miss your chance to take the Fabric Data Engineer (DP-600) exam for FREE! Find out how by attending the DP-600 session on April 23rd (pacific time), live or on-demand.
Learn moreNext up in the FabCon + SQLCon recap series: The roadmap for Microsoft SQL and Maximizing Developer experiences in Fabric. All sessions are available on-demand after the live show. Register now
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
| Dates | Closing stock actual | Target |
| 01-01-22 | 100 | 0 |
| 31-01-22 | 0 | 90 |
| 01-02-22 | 90 | 0 |
| 28-02-22 | 0 | 100 |
| 01-03-22 | 130 | 0 |
| 31-03-22 | 0 | 110 |
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.
Solved! Go to Solution.
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
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
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)
Regards,
Prabhu
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
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
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:
Best regards
If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.
A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.
| User | Count |
|---|---|
| 45 | |
| 43 | |
| 39 | |
| 19 | |
| 15 |
| User | Count |
|---|---|
| 67 | |
| 66 | |
| 31 | |
| 28 | |
| 24 |