Starting December 3, join live sessions with database experts and the Microsoft product team to learn just how easy it is to get started
Learn moreGet certified in Microsoft Fabric—for free! For a limited time, get a free DP-600 exam voucher to use by the end of 2024. Register now
In my recent quest to create or catalog as many DAX equivalents for Excel functions, as with DB, because DDB involves recursion, there is no "clean" DAX solution, it's ugly and you have to use reasonable maximum. 😞
DDB =
VAR __Cost = [Cost]
VAR __Salvage = [Salvage]
VAR __Life = [Life] * MAX('Table'[Lifetime Multiplier])
VAR __Period = MAX('Table'[Period])
VAR __Factor = IF(ISBLANK(MAX('Table'[Factor])),2,MAX('Table'[Factor]))
VAR __Rate = __Factor / __Life
VAR __Table1 = { (1, MINX( { (__Cost - 0) * __Rate, __Cost - __Salvage - 0 },[Value]) ) }
VAR __Table2 = { (2, MINX( { (__Cost - SUMX(__Table1,[Value2])) * __Rate, __Cost - __Salvage - SUMX(__Table1,[Value2]) },[Value])) }
VAR __Table3 = { (3, MINX( { (__Cost - SUMX(UNION(__Table1,__Table2),[Value2])) * __Rate, __Cost - __Salvage - SUMX(UNION(__Table1,__Table2),[Value2]) },[Value])) }
VAR __Table4 = { (4, MINX( { (__Cost - SUMX(UNION(__Table1,__Table2,__Table3),[Value2])) * __Rate, __Cost - __Salvage - SUMX(UNION(__Table1,__Table2,__Table3),[Value2]) },[Value])) }
VAR __Table5 = { (5, MINX( { (__Cost - SUMX(UNION(__Table1,__Table2,__Table3,__Table4),[Value2])) * __Rate, __Cost - __Salvage - SUMX(UNION(__Table1,__Table2,__Table3,__Table4),[Value2]) },[Value])) }
VAR __Table6 = { (6, MINX( { (__Cost - SUMX(UNION(__Table1,__Table2,__Table3,__Table4,__Table5),[Value2])) * __Rate, __Cost - __Salvage - SUMX(UNION(__Table1,__Table2,__Table3,__Table4,__Table5),[Value2]) },[Value])) }
VAR __Table7 = { (7, MINX( { (__Cost - SUMX(UNION(__Table1,__Table2,__Table3,__Table4,__Table5,__Table6),[Value2])) * __Rate, __Cost - __Salvage - SUMX(UNION(__Table1,__Table2,__Table3,__Table4,__Table5,__Table6),[Value2]) },[Value])) }
VAR __Table8 = { (8, MINX( { (__Cost - SUMX(UNION(__Table1,__Table2,__Table3,__Table4,__Table5,__Table6,__Table7),[Value2])) * __Rate, __Cost - __Salvage - SUMX(UNION(__Table1,__Table2,__Table3,__Table4,__Table5,__Table6,__Table7),[Value2]) },[Value])) }
VAR __Table9 = { (9, MINX( { (__Cost - SUMX(UNION(__Table1,__Table2,__Table3,__Table4,__Table5,__Table6,__Table7,__Table8),[Value2])) * __Rate, __Cost - __Salvage - SUMX(UNION(__Table1,__Table2,__Table3,__Table4,__Table5,__Table6,__Table7,__Table8),[Value2]) },[Value])) }
VAR __Table10 = { (10, MINX( { (__Cost - SUMX(UNION(__Table1,__Table2,__Table3,__Table4,__Table5,__Table6,__Table7,__Table8,__Table9),[Value2])) * __Rate, __Cost - __Salvage - SUMX(UNION(__Table1,__Table2,__Table3,__Table4,__Table5,__Table6,__Table7,__Table8,__Table9),[Value2]) },[Value])) }
VAR __Table11 = { (11, MINX( { (__Cost - SUMX(UNION(__Table1,__Table2,__Table3,__Table4,__Table5,__Table6,__Table7,__Table8,__Table9,__Table10),[Value2])) * __Rate, __Cost - __Salvage - SUMX(UNION(__Table1,__Table2,__Table3,__Table4,__Table5,__Table6,__Table7,__Table8,__Table9,__Table10),[Value2]) },[Value])) }
VAR __Table = UNION(__Table11,__Table10, __Table9,__Table8,__Table7,__Table6,__Table5,__Table4,__Table3,__Table2,__Table1)
RETURN
MAXX(FILTER(__Table,[Value1] = __Period),[Value2])
eyJrIjoiODdiOTIyOGItMGIwMC00NDQ4LTkzNmUtMDcyNGM1MTMyZWZkIiwidCI6IjRhMDQyNzQzLTM3M2EtNDNkMi04MjdiLTAwM2Y0YzdiYTFlNSIsImMiOjN9