The ultimate Fabric, Power BI, SQL, and AI community-led learning event. Save €200 with code FABCOMM.
Get registeredEnhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends September 15. Request your voucher.
I am calculating rolling depreciation based on the last available book value (Machine valuation after depreciation). I have fixed depreciation every month. The following dax is working as expected. The issue is when the depreciation becomes negative I am completely filtering it. But I want to show '1' as the Book value and stop from next month.
Eg:
Input data:
Machine | Acquisition amount | Depreciation amount | Book value Last month (Oct-2024) | date |
Machine 1 | 100,000 | 20,500 | 60,000 | 2024-11-01 |
Output:
Machine | Acquisition amount | Depreciation amount | Book value | date |
Machine 1 | 100,000 | 20,500 | 39,500 | 2024-12-01 |
Machine 1 | 100,000 | 20,500 | 19,000 | 2025-01-01 |
Machine 1 | 100,000 | 20,500 | -1,500 (Show 1 and stop) | 2025-02-01 |
Output (What happens if I consider < 1 and an If condition to show 1:
Machine | Acquisition amount | Depreciation amount | Book value | date |
Machine 1 | 100,000 | 20,500 | 39,500 | 2024-12-01 |
Machine 1 | 100,000 | 20,500 | 19,000 | 2025-01-01 |
Machine 1 | 100,000 | 20,500 | 1 | 2025-02-01 |
Machine 1 | 100,000 | 20,500 | 1 | 2025-03-01 |
Machine 1 | 100,000 | 20,500 | 1 | 2025-04-01 |
.... | .... | ... | .... | Continues till calendar table last date |
Rolling Book Value =
VAR staticDepreciation = CALCULATE(MAX('2024-11-11-converted'[Monthly depreciation amount]), REMOVEFILTERS('Calendar')) -- Fixed monthly depreciation
VAR StartDate = CALCULATE(MAX('2024-11-11-converted'[Custom]), REMOVEFILTERS('Calendar'))
VAR CurrentDate = MAX('Calendar'[Date]) -- Date in the visual row context
VAR InitialBookValue = CALCULATE(
MAX('2024-11-11-converted'[Book value at end of previous month]),
REMOVEFILTERS('Calendar') -- Remove Calendar table filters
) -- Starting book value
VAR MonthsElapsed = DATEDIFF(StartDate, CurrentDate, MONTH) + 1 -- Number of months from start date to current date
-- Calculate the Rolling Depreciated Value
VAR monthlyDepreciation = MonthsElapsed * staticDepreciation
VAR DepreciatedValue =
IF(
EDATE(StartDate, -1) <= CurrentDate, -- Ensure depreciation only happens from StartDate onward
InitialBookValue - monthlyDepreciation, -- Deduct depreciation month-by-month
BLANK() -- Return BLANK for rows before the StartDate
)
RETURN
IF(DepreciatedValue < 1,BLANK(), DepreciatedValue)
Solved! Go to Solution.
Hi @YogeshWaran2010 ,
I create a table as you mentioned.
Then I think you can create a new Calculated Column.
Column =
VAR BookValueNegative =
CALCULATE (
MIN ( 'Table'[Book value] ),
FILTER ( 'Table', 'Table'[Book value] < 0 )
)
RETURN
IF (
'Table'[Book value] < 0
|| 'Table'[date]
>= CALCULATE ( MIN ( 'Table'[date] ), FILTER ( 'Table', 'Table'[Book value] < 0 ) ),
1,
'Table'[Book value]
)
If you want to show things you want, I think you can create a new table.
Table 2 =
VAR _FirstOneDate =
CALCULATE ( MIN ( 'Table'[date] ), FILTER ( 'Table', 'Table'[Column] = 1 ) )
RETURN
FILTER ( 'Table', 'Table'[Column] <> 1 || 'Table'[date] = _FirstOneDate )
Best Regards
Yilong Zhou
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Hi @YogeshWaran2010 ,
I create a table as you mentioned.
Then I think you can create a new Calculated Column.
Column =
VAR BookValueNegative =
CALCULATE (
MIN ( 'Table'[Book value] ),
FILTER ( 'Table', 'Table'[Book value] < 0 )
)
RETURN
IF (
'Table'[Book value] < 0
|| 'Table'[date]
>= CALCULATE ( MIN ( 'Table'[date] ), FILTER ( 'Table', 'Table'[Book value] < 0 ) ),
1,
'Table'[Book value]
)
If you want to show things you want, I think you can create a new table.
Table 2 =
VAR _FirstOneDate =
CALCULATE ( MIN ( 'Table'[date] ), FILTER ( 'Table', 'Table'[Column] = 1 ) )
RETURN
FILTER ( 'Table', 'Table'[Column] <> 1 || 'Table'[date] = _FirstOneDate )
Best Regards
Yilong Zhou
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Hi @YogeshWaran2010 ,
To address your requirement of showing "1" only once after depreciation becomes negative or zero, you need to modify the DAX formula to ensure that once the book value reaches "1," it stays at "1" for all subsequent periods. This can be achieved by tracking whether the depreciation has reached the threshold and ensuring that subsequent calculations honor this state.
Here’s the modified DAX:
Rolling Book Value = VAR staticDepreciation = CALCULATE(MAX('2024-11-11-converted'[Monthly depreciation amount]), REMOVEFILTERS('Calendar')) -- Fixed monthly depreciation VAR StartDate = CALCULATE(MAX('2024-11-11-converted'[Custom]), REMOVEFILTERS('Calendar')) VAR CurrentDate = MAX('Calendar'[Date]) -- Date in the visual row context VAR InitialBookValue = CALCULATE( MAX('2024-11-11-converted'[Book value at end of previous month]), REMOVEFILTERS('Calendar') -- Remove Calendar table filters ) -- Starting book value VAR MonthsElapsed = DATEDIFF(StartDate, CurrentDate, MONTH) + 1 -- Number of months from start date to current date -- Calculate the Rolling Depreciated Value VAR monthlyDepreciation = MonthsElapsed * staticDepreciation VAR DepreciatedValue = IF( EDATE(StartDate, -1) <= CurrentDate, -- Ensure depreciation only happens from StartDate onward InitialBookValue - monthlyDepreciation, -- Deduct depreciation month-by-month BLANK() -- Return BLANK for rows before the StartDate ) -- Check if depreciation has already reached 1 in previous rows VAR HasReachedOne = CALCULATE( MINX( FILTER( ALL('Calendar'[Date]), 'Calendar'[Date] <= CurrentDate && DepreciatedValue <= 1 ), 1 ) ) -- Return the final value RETURN IF( HasReachedOne = 1, -- If "1" has already been reached 1, -- Continue showing "1" IF(DepreciatedValue < 1, 1, DepreciatedValue) -- Otherwise, calculate depreciation as normal )
Track If "1" Has Been Reached:
Conditional Logic:
Single "1" Logic:
For your example, this logic ensures that the book value transitions as follows:
This behavior aligns with your requirement to stop recalculating depreciation once the book value reaches "1." Let me know if you need further adjustments!
Please mark this as solution if it helps. Appreciate Kudos.
Hi @FarhanJeelani ,
Thank you for your response.
Sorry, I have made a mistake in the required output.
I want the output to check if the values go below 1 then show 1 and stop for consecutive months.
Output:
Machine | Acquisition amount | Depreciation amount | Book value | date |
Machine 1 | 100,000 | 20,500 | 39,500 | 2024-12-01 |
Machine 1 | 100,000 | 20,500 | 19,000 | 2025-01-01 |
Machine 1 | 100,000 | 20,500 | -1,500 (Show 1 and stop) | 2025-02-01 |
It stops at 2025-02-01 and 2025-03-01 is not printed. But in the shared Dax, consecutive and previous months also print '1'.
Note: Performance of the Dax is very poor after the modification.
User | Count |
---|---|
15 | |
13 | |
8 | |
6 | |
6 |
User | Count |
---|---|
24 | |
19 | |
12 | |
9 | |
7 |