Forum Discussion
Help with measure for rolling NPS
- 1 year ago
Hi zh1988
The Basic measures you need:Promoters = CALCULATE( COUNTROWS('fact_table'), 'fact_table'[nps score] >= 9 ) Detractors = CALCULATE( COUNTROWS('fact_table'), 'fact_table'[nps score] <= 6 ) TotalResponses = COUNTROWS('fact_table') NPS = DIVIDE( [Promoters] - [Detractors], [TotalResponses], 0 ) * 100
The Rolling Sums:RollingPromoters = VAR CurrentMonthOrder = MAX('DateTable'[MonthNumber]) VAR SelectedMonths = CALCULATETABLE( VALUES('DateTable'[MonthNumber]), ALLSELECTED('DateTable') ) VAR MinSelectedMonth = MINX(SelectedMonths, [MonthNumber]) RETURN CALCULATE( [Promoters], FILTER( ALL('DateTable'), 'DateTable'[MonthNumber] >= MinSelectedMonth && 'DateTable'[MonthNumber] <= CurrentMonthOrder ) ) RollingDetractors = VAR CurrentMonthOrder = MAX('DateTable'[MonthNumber]) VAR SelectedMonths = CALCULATETABLE( VALUES('DateTable'[MonthNumber]), ALLSELECTED('DateTable') ) VAR MinSelectedMonth = MINX(SelectedMonths, [MonthNumber]) RETURN CALCULATE( [Detractors], FILTER( ALL('DateTable'), 'DateTable'[MonthNumber] >= MinSelectedMonth && 'DateTable'[MonthNumber] <= CurrentMonthOrder ) ) RollingTotalResponses = VAR CurrentMonthOrder = MAX('DateTable'[MonthNumber]) VAR SelectedMonths = CALCULATETABLE( VALUES('DateTable'[MonthNumber]), ALLSELECTED('DateTable') ) VAR MinSelectedMonth = MINX(SelectedMonths, [MonthNumber]) RETURN CALCULATE( [TotalResponses], FILTER( ALL('DateTable'), 'DateTable'[MonthNumber] >= MinSelectedMonth && 'DateTable'[MonthNumber] <= CurrentMonthOrder ) )
Rolling perc & NPS:RollingPromotersPct = DIVIDE( [RollingPromoters], [RollingTotalResponses], 0 ) RollingDetractorsPct = DIVIDE( [RollingDetractors], [RollingTotalResponses], 0 ) RollingNPS = DIVIDE( [RollingPromoters] - [RollingDetractors], [RollingTotalResponses], 0 ) * 100
Please do mention the kind of issue faced or what discrepancy occurs if this doesn't help - 1 year ago
Hi there, thank you very much!! When first applying the measures it did not take the year slicer into account (I also did not mention that explicitly) so the totals were based on the complete data set, but by adding a month key into allmeasures it now shows correct data.
RollingPromoters_monthkey =VAR CurrentMonthKey = MAX('dim_date'[Year]) * 100 + MAX('dim_date'[Month])VAR SelectedMonthKeys =SELECTCOLUMNS(FILTER(ALLSELECTED('dim_date'),NOT(ISBLANK('dim_date'[Month])) &&NOT(ISBLANK('dim_date'[Year]))),"MonthKey", 'dim_date'[Year] * 100 + 'dim_date'[Month])VAR MinSelectedMonthKey = MINX(SelectedMonthKeys, [MonthKey])RETURNCALCULATE([Promoters],FILTER(ALL('dim_date'),('dim_date'[Year] * 100 + 'dim_date'[Month]) >= MinSelectedMonthKey &&('dim_date'[Year] * 100 + 'dim_date'[Month]) <= CurrentMonthKey &&('dim_date'[Year] * 100 + 'dim_date'[Month]) IN SelectedMonthKeys))
😃😃
Hi zh1988 ,
Hope this helps:
Rolling NPS Selected Months =
VAR CurrentMonth = MAX('DateTable'[MonthStartDate])
VAR RollingPromoters =
CALCULATE(
COUNTROWS('fact_table'),
'fact_table'[nps score] >= 9,
FILTER(
ALLSELECTED('DateTable'),
'DateTable'[MonthStartDate] <= CurrentMonth
)
)
VAR RollingDetractors =
CALCULATE(
COUNTROWS('fact_table'),
'fact_table'[nps score] <= 6,
FILTER(
ALLSELECTED('DateTable'),
'DateTable'[MonthStartDate] <= CurrentMonth
)
)
VAR RollingTotal =
CALCULATE(
COUNTROWS('fact_table'),
FILTER(
ALLSELECTED('DateTable'),
'DateTable'[MonthStartDate] <= CurrentMonth
)
)
RETURN
DIVIDE(RollingPromoters - RollingDetractors, RollingTotal, 0)