Forum Discussion
Mastermayank26
Microsoft Employee
1 year agoCircular Dependency Error in Power BI Measure
HI All, I am trying to recreate excel formula in Power BI which is causing circular dependency in the measure.Please find below my scenario: I have a table with MMYYY, Total Sales, MM...
- 1 year ago
Hi Mastermayank26 i tried implementing this, almost there.... I guess the issue might be in the last section where it calculates the forecasted sales after the last sales month. Could you take a look?
Forecast Sales =VAR CurrentMonth = MAX('Date'[Date])-- Get previous month's start and end datesVAR PrevMonthStart =DATE(YEAR(CurrentMonth), MONTH(CurrentMonth) - 1, 1)VAR PrevMonthEnd =EOMONTH(PrevMonthStart, 0)-- Calculate Total Sales for the previous monthVAR PrevMonthSales =CALCULATE([Total Sales],FILTER(ALL('Date'),'Date'[Date] >= PrevMonthStart && 'Date'[Date] <= PrevMonthEnd))-- Get the last month of actual sales dataVAR LastSalesMonth =CALCULATE(MAX('Date'[Date]),FILTER(ALL('Date'),[Total Sales] > 0))VAR MonthsAhead =DATEDIFF(LastSalesMonth, CurrentMonth, MONTH)RETURNIF (ISBLANK(PrevMonthSales) && MonthsAhead > 0,PrevMonthSales + 100 * MonthsAhead ,PrevMonthSales)
techies
Super User
1 year agoHi Mastermayank26 please check this forecast measure
Forecast Sales =
VAR CurrentMonth = MAX('Date'[Date])
VAR LastActualMonth =
CALCULATE (
MAX('Date'[Date]),
FILTER(
ALL('Date'),
NOT(ISBLANK([Total Sales]))
)
)
VAR MonthsAhead =
DATEDIFF(LastActualMonth, CurrentMonth, MONTH)
VAR LastActualSales =
CALCULATE (
[Total Sales],
'Date'[Date] = LastActualMonth
)
RETURN
IF (
ISBLANK([Total Sales]) && MonthsAhead > 0,
LastActualSales + (MonthsAhead * 100),
[Total Sales]
)