Forum Discussion
Recursive Calculation and Forecast measure
- 3 years ago
Hi murillocosta
Such fully recursive problems cannot be handled by DAX straight forward. A helper table that suits your case shall be needed to handle the recursion. The solution is a bet difficult to understand and it should be carefully design to suit each case independently (cannot be generalized) nevertheless, what ever the chosen details of the solution, the general idea remains the same.You need to import the Fibonacci table as is and use the DAX as is. However, your real data might not be as I expected, therefore some changes might be required.
Please note that such reports should have limited flexibility in terms of the columns used to slice. Slicing by different column(s) might require changing the code. You need to understand that this is a limitation of the DAX language for the time being, hopping future updates will curry new features of the language such as loops that can help performing recursive calculations much more easier.
Also Please note that there is a rounding error with this method and the results shall not be 100% accurate.
Please refer to the sample file with the solutionForecast Count = VAR W = CALCULATE ( MAX ( 'Table'[Year Week Sort] ), REMOVEFILTERS ( ) ) -- with real data would be VAR LastDateWithData 'Table'[Date] and then VAR W = YEAR ( LastDateWithData ) * 100 + WEEKNUM ( LastDateWithData ) VAR CW = MAX ( 'Date'[Year Week Sort] ) VAR S4 = CALCULATE ( [CounRef], 'Date'[Year Week Sort] = W, ALLSELECTED ( ) ) VAR S3 = CALCULATE ( [CounRef], 'Date'[Year Week Sort] = W - 1, ALLSELECTED ( ) ) VAR S2 = CALCULATE ( [CounRef], 'Date'[Year Week Sort] = W - 2, ALLSELECTED ( ) ) VAR S1 = CALCULATE ( [CounRef], 'Date'[Year Week Sort] = W - 3, ALLSELECTED ( ) ) VAR SelectedWeeks = ALLSELECTED ( 'Date'[Year Week Sort] ) VAR WeeksOnAndBefore = FILTER ( SelectedWeeks, 'Date'[Year Week Sort] > W && 'Date'[Year Week Sort] <= CW ) VAR Ranking = COUNTROWS ( WeeksOnAndBefore ) RETURN SUMX ( FILTER ( FibonacciTable, FibonacciTable[Index] = Ranking ), FibonacciTable[Value1] * S1 + FibonacciTable[Value2] * S2 + FibonacciTable[Value3] * S3 + FibonacciTable[Value3] * S4 ) - 3 years ago
murillocosta
Here you go
Hi vitorcampos
Glad that you found that helpful.
Regarding your question, to be honest I have not been following up on this subject for some time. I'm not aware of any other method. In fact he Fibonacci table is some that I have invented couple of years ago to tackle this issue of recursion following mathematical approach.
As far as I know Greg_Deckler was following up on this subject since long time ago. I believe no one can advise on this subject better than he can do.
Hello again, tamerj1.
I've made the necessary adjustments for my project based on your fantastic metric.
However, I'm currently struggling with creating a Year-to-Date metric by combining real and projected values.
Could you provide me with a clue on how to formulate a YTD measure that incorporates both types of data (real and projected ones)?