Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
Anonymous
Not applicable

DAX for NPS

Hi,

 

I need to calculate NPS Score but only need to look at latest reponses (By Date) and respective topics.

I am starting with Promotor and Detractors for now .Below is the data and expected output. 

If I get dyamic ranking for it , should be able to filter based on Rank for Promotors and detractors.

Started with Rank but having a hardtime in incorporating topicwise rating...

 

Any help is appreciated.

 

Ranks = RANKX(FILTER(Table,Table[Person_EmpID]=EARLIER(Table[Person_EmpID])),Table[Date].[Date],,ASC,Dense)

 

Here is the raw data

TopicPerson NameRatingDate
AAdam1011/20/2019
AAdam911/28/2019
AAdam411/29/2019
BAdam311/30/2019
ABen1010/30/2019
ABen910/20/2019
ABen311/5/2019
BBen111/3/2019
BBen211/4/2019

Below is the expected output

 

 

TopicPerson NameScoreDatePromotor By Topic Detractor By TopicPromotor OverallDetractor Overall
AAdam1011/20/2019    
AAdam911/28/20191 1 
AAdam411/29/2019 1  
BAdam311/30/2019 1 1
ABen1010/30/20191 1 
ABen910/20/2019    
ABen311/5/2019 1 1
BBen111/3/2019    
BBen211/4/2019 1  

 

 

Thanks

1 ACCEPTED SOLUTION

Hi @Anonymous ,

 

In that case you might need a Calendar table and SELECTEDVALUE() function.

Please refer to below measures and see if the result achieve your expectation:

Promotor By Topic = 
IF (
    ISFILTERED ( 'Table 2'[YearMonth] ),
    IF (
        MAX ( 'Table'[Date] )
            = CALCULATE (
                MAX ( 'Table'[Date] ),
                FILTER (
                    ALLEXCEPT ( 'Table', 'Table'[Person Name], 'Table'[Topic] ),
                    'Table'[Rating] >= 9
                        && FORMAT ( 'Table'[Date], "YYYYMM" ) <= SELECTEDVALUE ( 'Table 2'[YearMonth] )
                )
            ),
        1,
        ""
    ),
    IF (
        MAX ( 'Table'[Date] )
            = CALCULATE (
                MAX ( 'Table'[Date] ),
                FILTER (
                    ALLEXCEPT ( 'Table', 'Table'[Person Name], 'Table'[Topic] ),
                    'Table'[Rating] >= 9
                )
            ),
        1,
        ""
    )
)
Detractor By Topic = 
IF (
    ISFILTERED ( 'Table 2'[YearMonth] ),
    IF (
        MAX ( 'Table'[Date] )
            = CALCULATE (
                MAX ( 'Table'[Date] ),
                FILTER (
                    ALLEXCEPT ( 'Table', 'Table'[Person Name], 'Table'[Topic] ),
                    FORMAT ( 'Table'[Date], "YYYYMM" ) <= SELECTEDVALUE ( 'Table 2'[YearMonth] )
                )
            ),
        1,
        ""
    ),
    IF (
        MAX ( 'Table'[Date] )
            = CALCULATE (
                MAX ( 'Table'[Date] ),
                ALLEXCEPT ( 'Table', 'Table'[Person Name], 'Table'[Topic] )
            ),
        1,
        ""
    )
)
Promotor Overall = 
IF (
    ISFILTERED ( 'Table 2'[YearMonth] ),
    IF (
        MAX ( 'Table'[Date] )
            = CALCULATE (
                MAX ( 'Table'[Date] ),
                FILTER (
                    ALLEXCEPT ( 'Table', 'Table'[Person Name] ),
                    'Table'[Rating] >= 9
                        && FORMAT ( 'Table'[Date], "YYYYMM" ) <= SELECTEDVALUE ( 'Table 2'[YearMonth] )
                )
            ),
        1,
        ""
    ),
    IF (
        MAX ( 'Table'[Date] )
            = CALCULATE (
                MAX ( 'Table'[Date] ),
                FILTER ( ALLEXCEPT ( 'Table', 'Table'[Person Name] ), 'Table'[Rating] >= 9 )
            ),
        1,
        ""
    )
)
Detractor Overall = 
IF (
    ISFILTERED ( 'Table 2'[YearMonth] ),
    IF (
        MAX ( 'Table'[Date] )
            = CALCULATE (
                MAX ( 'Table'[Date] ),
                FILTER (
                    ALLEXCEPT ( 'Table', 'Table'[Person Name] ),
                    FORMAT ( 'Table'[Date], "YYYYMM" ) <= SELECTEDVALUE ( 'Table 2'[YearMonth] )
                )
            ),
        1,
        ""
    ),
    IF (
        MAX ( 'Table'[Date] )
            = CALCULATE ( MAX ( 'Table'[Date] ), ALLEXCEPT ( 'Table', 'Table'[Person Name] ) ),
        1,
        ""
    )
)

Result would be shown as below:

1.PNG

2.PNG

3.PNG

BTW, Pbix as attached, hopefully works you.

 

Best Regards,

Jay

Community Support Team _ Jay Wang

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Community Support Team _ Jay
If this post helps, then please consider Accept it as the solution
to help the other members find it.

View solution in original post

4 REPLIES 4
v-jayw-msft
Community Support
Community Support

Hi @Anonymous ,

 

I managed to figure out the Detractors but failed about Promotors. Actually, I couldn't understand what the Promotors is according to your expected output.

Please check following measures and see if the result achieve your expectation:

 

Promotor By Topic = IF(MAX('Table'[Date]) = CALCULATE(MIN('Table'[Date]),ALLEXCEPT('Table','Table'[Person Name],'Table'[Topic])),1,"")
Detractor By Topic = IF(MAX('Table'[Date]) = CALCULATE(MAX('Table'[Date]),ALLEXCEPT('Table','Table'[Person Name],'Table'[Topic])),1,"")
Promotor Overall = IF(MAX('Table'[Date]) = CALCULATE(MIN('Table'[Date]),ALLEXCEPT('Table','Table'[Person Name])),1,"")
Promotor By Topic = IF(MAX('Table'[Date]) = CALCULATE(MIN('Table'[Date]),ALLEXCEPT('Table','Table'[Person Name],'Table'[Topic])),1,"")

 

Result would be shown as below:

1.PNG

 

Best Regards,

Jay

Community Support Team _ Jay Wang

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Community Support Team _ Jay
If this post helps, then please consider Accept it as the solution
to help the other members find it.
Anonymous
Not applicable

Thanks for that.

Promotors are score between 9 and 10.

 

The DAX you provided works after chnaging MIN to MAX  but If anyone changes the date slicer it doesn't chnage with it.

If its showing a count of 1 for November , It doesn't show count 1 for Oct dynamically even though slicer has changed until Oct.

IF(MAX('Table'[Date]) = CALCULATE(MAX('Table'[Date]),ALLEXCEPT('Table','Table'[Person Name],'Table'[Topic])),1,"")

Hi @Anonymous ,

 

In that case you might need a Calendar table and SELECTEDVALUE() function.

Please refer to below measures and see if the result achieve your expectation:

Promotor By Topic = 
IF (
    ISFILTERED ( 'Table 2'[YearMonth] ),
    IF (
        MAX ( 'Table'[Date] )
            = CALCULATE (
                MAX ( 'Table'[Date] ),
                FILTER (
                    ALLEXCEPT ( 'Table', 'Table'[Person Name], 'Table'[Topic] ),
                    'Table'[Rating] >= 9
                        && FORMAT ( 'Table'[Date], "YYYYMM" ) <= SELECTEDVALUE ( 'Table 2'[YearMonth] )
                )
            ),
        1,
        ""
    ),
    IF (
        MAX ( 'Table'[Date] )
            = CALCULATE (
                MAX ( 'Table'[Date] ),
                FILTER (
                    ALLEXCEPT ( 'Table', 'Table'[Person Name], 'Table'[Topic] ),
                    'Table'[Rating] >= 9
                )
            ),
        1,
        ""
    )
)
Detractor By Topic = 
IF (
    ISFILTERED ( 'Table 2'[YearMonth] ),
    IF (
        MAX ( 'Table'[Date] )
            = CALCULATE (
                MAX ( 'Table'[Date] ),
                FILTER (
                    ALLEXCEPT ( 'Table', 'Table'[Person Name], 'Table'[Topic] ),
                    FORMAT ( 'Table'[Date], "YYYYMM" ) <= SELECTEDVALUE ( 'Table 2'[YearMonth] )
                )
            ),
        1,
        ""
    ),
    IF (
        MAX ( 'Table'[Date] )
            = CALCULATE (
                MAX ( 'Table'[Date] ),
                ALLEXCEPT ( 'Table', 'Table'[Person Name], 'Table'[Topic] )
            ),
        1,
        ""
    )
)
Promotor Overall = 
IF (
    ISFILTERED ( 'Table 2'[YearMonth] ),
    IF (
        MAX ( 'Table'[Date] )
            = CALCULATE (
                MAX ( 'Table'[Date] ),
                FILTER (
                    ALLEXCEPT ( 'Table', 'Table'[Person Name] ),
                    'Table'[Rating] >= 9
                        && FORMAT ( 'Table'[Date], "YYYYMM" ) <= SELECTEDVALUE ( 'Table 2'[YearMonth] )
                )
            ),
        1,
        ""
    ),
    IF (
        MAX ( 'Table'[Date] )
            = CALCULATE (
                MAX ( 'Table'[Date] ),
                FILTER ( ALLEXCEPT ( 'Table', 'Table'[Person Name] ), 'Table'[Rating] >= 9 )
            ),
        1,
        ""
    )
)
Detractor Overall = 
IF (
    ISFILTERED ( 'Table 2'[YearMonth] ),
    IF (
        MAX ( 'Table'[Date] )
            = CALCULATE (
                MAX ( 'Table'[Date] ),
                FILTER (
                    ALLEXCEPT ( 'Table', 'Table'[Person Name] ),
                    FORMAT ( 'Table'[Date], "YYYYMM" ) <= SELECTEDVALUE ( 'Table 2'[YearMonth] )
                )
            ),
        1,
        ""
    ),
    IF (
        MAX ( 'Table'[Date] )
            = CALCULATE ( MAX ( 'Table'[Date] ), ALLEXCEPT ( 'Table', 'Table'[Person Name] ) ),
        1,
        ""
    )
)

Result would be shown as below:

1.PNG

2.PNG

3.PNG

BTW, Pbix as attached, hopefully works you.

 

Best Regards,

Jay

Community Support Team _ Jay Wang

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Community Support Team _ Jay
If this post helps, then please consider Accept it as the solution
to help the other members find it.

Hi @Anonymous ,

 

Has the question been solved, did my answer help you?

Could you please accept my post as the solution if it helps?

Please feel free to ask if you have any questions.

 

Best Regards,

Jay

Community Support Team _ Jay Wang

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Community Support Team _ Jay
If this post helps, then please consider Accept it as the solution
to help the other members find it.

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.