Share feedback directly with Fabric product managers, participate in targeted research studies and influence the Fabric roadmap.
Sign up nowGet Fabric certified for FREE! Don't miss your chance! Learn more
Hi All -
Can anyone help me debug my code -- I'm building a time series and want to show NPS (all clients), NPS (Client Group 1), NPS (Client Group 2), etc. The Client Group designation lives on another table, but they are tied together in my model.
The expression provides the accurate net promoter score without a filter context, but once I throw that filter context on, nothing actually changes in terms of the score -- however, when I physically add the field as a filter on the visual and select 'Client Group 1', for example, I get the proper NPS for Client Group 1.
Since these are all going to be living on the same line graph, I'm trying to create a custom measure for each. Appreciate any advice - hopefully, it's something super simple that I'm just not catching being relatively new to the wonderful world of DAX! 🙂
NPS Calc (Client Group 1) =
VAR Promoter =
VAR Detractor =
VAR prom_minus_detractor = promoter-detractor
RETURN
CALCULATE(DIVIDE(prom_minus_detractor , ALL_NPS), 'Clients'[Client_Group] in {"Client Group 1"})
Thank you in advance!!
Solved! Go to Solution.
@samdep
When you use Variables as Expressions inside CALCULATE, they are not evaluated by the filters in CALCULATE, variables are constant.Try the following modified version:
NPS Calc (Client Group 1) =
CALCULATE (
DIVIDE (
VAR Promoter =
CALCULATE (
COUNTA ( 'Simple Survey'[MASTER NPS FIELD 1] ),
'Simple Survey'[MASTER NPS FIELD 1] IN { "Promoter" }
)
VAR Detractor =
CALCULATE (
COUNTA ( 'Simple Survey'[MASTER NPS FIELD 1] ),
'Simple Survey'[MASTER NPS FIELD 1] IN { "Detractor" }
)
VAR prom_minus_detractor = promoter - detractor
RETURN
prom_minus_detractor,
VAR All_NPS =
CALCULATE (
COUNTA ( 'Simple Survey'[MASTER NPS FIELD 1] ),
'Simple Survey'[MASTER NPS FIELD 1] IN { "Detractor", "Promoter", "Passive" }
)
RETURN
All_NPS
),
'Clients'[Client_Group] IN { "Client Group 1" }
)
⭕ Subscribe and learn Power BI from these videos
⚪ Website ⚪ LinkedIn ⚪ PBI User Group
@samdep
When you use Variables as Expressions inside CALCULATE, they are not evaluated by the filters in CALCULATE, variables are constant.Try the following modified version:
NPS Calc (Client Group 1) =
CALCULATE (
DIVIDE (
VAR Promoter =
CALCULATE (
COUNTA ( 'Simple Survey'[MASTER NPS FIELD 1] ),
'Simple Survey'[MASTER NPS FIELD 1] IN { "Promoter" }
)
VAR Detractor =
CALCULATE (
COUNTA ( 'Simple Survey'[MASTER NPS FIELD 1] ),
'Simple Survey'[MASTER NPS FIELD 1] IN { "Detractor" }
)
VAR prom_minus_detractor = promoter - detractor
RETURN
prom_minus_detractor,
VAR All_NPS =
CALCULATE (
COUNTA ( 'Simple Survey'[MASTER NPS FIELD 1] ),
'Simple Survey'[MASTER NPS FIELD 1] IN { "Detractor", "Promoter", "Passive" }
)
RETURN
All_NPS
),
'Clients'[Client_Group] IN { "Client Group 1" }
)
⭕ Subscribe and learn Power BI from these videos
⚪ Website ⚪ LinkedIn ⚪ PBI User Group
This worked perfectly, thank you! I didn't realize what you'd said about variables being constant, so that's good to know - thank you!
If you love stickers, then you will definitely want to check out our Community Sticker Challenge!
Check out the January 2026 Power BI update to learn about new features.
| User | Count |
|---|---|
| 5 | |
| 4 | |
| 4 | |
| 3 | |
| 2 |
| User | Count |
|---|---|
| 15 | |
| 9 | |
| 9 | |
| 7 | |
| 5 |