The ultimate Microsoft Fabric, Power BI, Azure AI, and SQL learning event! Join us in Stockholm, Sweden from September 24-27, 2024.
2-for-1 sale on June 20 only!
Find everything you need to get certified on Fabric—skills challenges, live sessions, exam prep, role guidance, and more. Get started
I'm working on some calculations for capital budgeting, and I have the following two tables in my data model:
I'm trying to build out a calculated column in DAX to determine the payback period for each project in the Project table. I've put together the calculation here, I'm just not sure exactly how to execute this in DAX.
Logical Steps for Calculating Payback Period:
For each Project, find the cumulative sum for each date for relevant metrics (Include OpEx Savings and OpEx Implementation Cost, but not Revenue or Working Capital)
Find the MIN date where cumulative sum is greater than zero (the "break-even" date")
Find the MIN date with non-zero implementation cost ("Investment date")
Find the difference (in months) between #2 and #3 to determine payback period
Solved! Go to Solution.
After a fair amount of trial and error, I came up with a solution.
Step 1: Build out a helper metrics table. This serves 2 purposes: (a) excludes irrelevant metrics (like revenue), and (b) ensure costs are negative and savings are positive.
Step 2: Build 2 helper measures that will go into the virtual, summarized, intermediate table.
CumulativeTotalMetric:=CALCULATE ( SUMX ( Impact, Impact[Latest Estimate Monthly Values] * RELATED ( BaseMetrics[Payback Period Multiplier] ) ), FILTER ( ALL ( Impact[Month] ), Impact[Month] <= MAX ( Impact[Month] ) ) )
TotalMetric:=SUMX ( Impact, Impact[Latest Estimate Monthly Values] * RELATED ( BaseMetrics[Payback Period Multiplier] ) )
Step 3: Create the final measure that creates the virtual table (BaseTable), and performs logical operations on it to arrive at the final payback period.
Payback Period (Years):=
VAR BaseTable = ADDCOLUMNS ( SUMMARIZE ( Impact, Impact[initiative #], Impact[snapshot], Impact[Month] ), "Cumulative Total Impact", CALCULATE ( [CumulativeTotalMetric] ), "Total Impact", CALCULATE ( [TotalMetric] ) ) VAR LastCumulativeLossDate = MAXX ( FILTER ( BaseTable, [Cumulative Total Impact] < 0 ), [Month] ) VAR BreakEvenDate = MINX ( FILTER ( BaseTable, [Month] > LastCumulativeLossDate && [Cumulative Total Impact] > 0 ), [Month] ) VAR InitialInvestmentDate = MINX ( FILTER ( BaseTable, [Total Impact] < 0 ), [Month] ) RETURN IF ( OR ( ISBLANK ( InitialInvestmentDate ), ISBLANK ( BreakEvenDate ) ), BLANK (), ( BreakEvenDate - InitialInvestmentDate ) / 365 )
This last meaure is pretty complicated. It uses progressive, dependent variables. It starts with the same base table, and defines variables that are used in subsequent variables. I'm no DAX expert, but I suspect using these variables helps with the calculation efficiency.
After a fair amount of trial and error, I came up with a solution.
Step 1: Build out a helper metrics table. This serves 2 purposes: (a) excludes irrelevant metrics (like revenue), and (b) ensure costs are negative and savings are positive.
Step 2: Build 2 helper measures that will go into the virtual, summarized, intermediate table.
CumulativeTotalMetric:=CALCULATE ( SUMX ( Impact, Impact[Latest Estimate Monthly Values] * RELATED ( BaseMetrics[Payback Period Multiplier] ) ), FILTER ( ALL ( Impact[Month] ), Impact[Month] <= MAX ( Impact[Month] ) ) )
TotalMetric:=SUMX ( Impact, Impact[Latest Estimate Monthly Values] * RELATED ( BaseMetrics[Payback Period Multiplier] ) )
Step 3: Create the final measure that creates the virtual table (BaseTable), and performs logical operations on it to arrive at the final payback period.
Payback Period (Years):=
VAR BaseTable = ADDCOLUMNS ( SUMMARIZE ( Impact, Impact[initiative #], Impact[snapshot], Impact[Month] ), "Cumulative Total Impact", CALCULATE ( [CumulativeTotalMetric] ), "Total Impact", CALCULATE ( [TotalMetric] ) ) VAR LastCumulativeLossDate = MAXX ( FILTER ( BaseTable, [Cumulative Total Impact] < 0 ), [Month] ) VAR BreakEvenDate = MINX ( FILTER ( BaseTable, [Month] > LastCumulativeLossDate && [Cumulative Total Impact] > 0 ), [Month] ) VAR InitialInvestmentDate = MINX ( FILTER ( BaseTable, [Total Impact] < 0 ), [Month] ) RETURN IF ( OR ( ISBLANK ( InitialInvestmentDate ), ISBLANK ( BreakEvenDate ) ), BLANK (), ( BreakEvenDate - InitialInvestmentDate ) / 365 )
This last meaure is pretty complicated. It uses progressive, dependent variables. It starts with the same base table, and defines variables that are used in subsequent variables. I'm no DAX expert, but I suspect using these variables helps with the calculation efficiency.
Join the community in Stockholm for expert Microsoft Fabric learning including a very exciting keynote from Arun Ulag, Corporate Vice President, Azure Data.
Check out the June 2024 Power BI update to learn about new features.
User | Count |
---|---|
105 | |
97 | |
81 | |
62 | |
54 |
User | Count |
---|---|
246 | |
119 | |
114 | |
87 | |
70 |