Forum Discussion
Iteration should work until the condition get pass
Hi, My requirement the iteration should work automatically if the condition get fail...
SharmilaBrisca , Try using
Days =
VAR MaxMonth = MAX('Date Table'[Date])
VAR MaxDays = MAX('Date Table'[Days in Month])
VAR MaxSales = [CM Sales]
VAR MaxOutstanding = [Total Outstanding]
VAR Result =
IF(
MaxSales >= MaxOutstanding,
MaxDays,
VAR DaysInMonth = MaxDays
VAR Difference = MaxOutstanding - MaxSales
VAR MonthCounter = 1
VAR LoopResult =
WHILE(
TRUE(),
VAR PrevMonth = DATEADD(MaxMonth, -MonthCounter, MONTH)
VAR PrevSales = CALCULATE([CM Sales], PrevMonth)
VAR PrevDays = CALCULATE(MAX('Date Table'[Days in Month]), PrevMonth)
VAR NewDifference = Difference - PrevSales
VAR NewDaysInMonth = DaysInMonth + (Difference / (PrevSales / PrevDays))
RETURN
IF(
PrevSales >= Difference,
NewDaysInMonth,
VAR NewMonthCounter = MonthCounter + 1
VAR NewDifference = NewDifference
VAR NewDaysInMonth = NewDaysInMonth
RETURN
IF(
NewDifference <= 0,
NewDaysInMonth,
BLANK()
)
)
)
RETURN LoopResult
)
RETURN Result
- SharmilaBrisca1 year agoResolver I
Hi,
The measure you have returned is having error in LoopResult variable.