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
junglejimsvet
Helper I
Helper I

Reporting only the latest customer reaction in a given time window/topic and reporting change over t

Hi All,

 

I'm guessing I need to use some combination of Summarize and Group but don't yet have the skills and was hoping that someone could help me:)  Example excel file here customer shift example.xlsx  (apologies it won't let me upload directly to the forum)

 

Part 1:  

  • Customers are seen multiple times on multiple topics over time and we record a "Reaction" to the topic
  • I want to report the current landscape of customers latest reactions against the topics (so if Jim was seen 3 times on topic X, I only want to count the latest dated "Reaction" in the table
  • So my question is what dax do I use to take the reaction at the max date for a given customer and topic
  # Customers
Parent TopicChild TopicNegativeNeutralPositive
Politics and EconomyPolitics022
Politics and EconomyEconomy111
Weather and FootballWeather011
Weather and FootballFootball110

 

 

Part 2:  We also want to assess the average shift in reaction for a given topic over time (so if a customer shifts from 1 to 3 in reaction there is a shift of 2, we then average that with all of the other customers who have been seen more than once)

  # Customers 
Parent TopicChild TopicAverage Shift 
Politics and EconomyPolitics1.5Jim moved from 1 to 3, Milly Moved from 2 to 3… avg = (2+1)/2 = 1.5
Politics and EconomyEconomy1Only Alex seen multiple times from 1 to 2
Weather and FootballWeather1Only Alex seen multiple times from 1 to 3
Weather and FootballFootballN/ANo one see more than once

Question:  how do I write the dax to pull the earliest and latest reactions for a given customer / topic combination

 

 

Many thanks,

 

Jim

 

 

Below is the dummy data as shown on the link (in case link does not work)

Call NameCountryCustomer IDCustomer NameDateParent TopicChild TopicReactionReaction as numberPriority Conversation

1UK4Jim01-JanPolitics and EconomyPoliticsNegative1Y
13UK5John01-JanPolitics and EconomyPoliticsNeutral2Y
21UK7Alex03-JanWeather and FootballWeatherNegative1N
55UK5John03-JanPolitics and EconomyEconomyNegative1Y
123UK7Alex06-JanWeather and FootballWeatherNeutral2N
123UK7Alex06-JanPolitics and EconomyEconomyNegative1Y
132UK1Henry08-JanWeather and FootballWeatherPositive3Y
154UK2Milly08-JanPolitics and EconomyPoliticsNeutral2Y
321UK6Matt08-JanWeather and FootballFootballNeutral2N
516UK7Alex16-JanWeather and FootballWeatherNeutral2Y
516UK7Alex16-JanPolitics and EconomyEconomyNeutral2Y
516UK7Alex16-JanWeather and FootballFootballNegative1N
1846UK3Annie17-JanPolitics and EconomyEconomyPositive3Y
4564UK7Alex21-JanPolitics and EconomyPoliticsNeutral2Y
5231UK4Jim21-JanPolitics and EconomyPoliticsPositive3Y
6854UK2Milly23-JanPolitics and EconomyPoliticsPositive3Y
21352UK7Alex29-JanPolitics and EconomyEconomyNeutral2Y

 

 

 

1 ACCEPTED SOLUTION
v-jianboli-msft
Community Support
Community Support

Hi @junglejimsvet ,

 

Please try:

Negative = 
VAR _a =
    SUMMARIZE (
        'Table',
        'Table'[Parent Topic],
        'Table'[Child Topic],
        'Table'[Customer ID],
        "Reaction",
            CALCULATE (
                MAX ( 'Table'[Reaction] ),
                FILTER ( 'Table', [Date] = MAX ( 'Table'[Date] ) )
            )
    )
RETURN
    COUNTX ( FILTER ( _a, [Reaction] = "Negative" ), [Customer ID] )

Neutral = 
VAR _a =
    SUMMARIZE (
        'Table',
        'Table'[Parent Topic],
        'Table'[Child Topic],
        'Table'[Customer ID],
        "Reaction",
            CALCULATE (
                MAX ( 'Table'[Reaction] ),
                FILTER ( 'Table', [Date] = MAX ( 'Table'[Date] ) )
            )
    )
RETURN
    COUNTX ( FILTER ( _a, [Reaction] = "Neutral" ), [Customer ID] )


Positive = 
VAR _a =
    SUMMARIZE (
        'Table',
        'Table'[Parent Topic],
        'Table'[Child Topic],
        'Table'[Customer ID],
        "Reaction",
            CALCULATE (
                MAX ( 'Table'[Reaction] ),
                FILTER ( 'Table', [Date] = MAX ( 'Table'[Date] ) )
            )
    )
RETURN
    COUNTX ( FILTER ( _a, [Reaction] = "Positive" ), [Customer ID] )

Average Shift = 
VAR _a =
    SUMMARIZE (
        'Table',
        'Table'[Parent Topic],
        'Table'[Child Topic],
        'Table'[Customer ID],
        'Table'[Reaction]
    )
VAR _b =
    SUMMARIZE (
        _a,
        'Table'[Parent Topic],
        'Table'[Child Topic],
        'Table'[Customer ID],
        "Shift",
            IF (
                COUNTX ( 'Table', [Reaction] ) > 1,
                CALCULATE (
                    MAX ( 'Table'[Reaction as number] ),
                    FILTER ( 'Table', [Call Name] = MAX ( 'Table'[Call Name] ) )
                )
                    - CALCULATE (
                        MIN ( 'Table'[Reaction as number] ),
                        FILTER ( 'Table', [Call Name] = MIN ( 'Table'[Call Name] ) )
                    )
            )
    )
RETURN
    AVERAGEX ( _b, [Shift] )

Final output:

vjianbolimsft_0-1688103190788.png

Best Regards,

Jianbo Li

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

View solution in original post

4 REPLIES 4
v-jianboli-msft
Community Support
Community Support

Hi @junglejimsvet ,

 

Please try:

Negative = 
VAR _a =
    SUMMARIZE (
        'Table',
        'Table'[Parent Topic],
        'Table'[Child Topic],
        'Table'[Customer ID],
        "Reaction",
            CALCULATE (
                MAX ( 'Table'[Reaction] ),
                FILTER ( 'Table', [Date] = MAX ( 'Table'[Date] ) )
            )
    )
RETURN
    COUNTX ( FILTER ( _a, [Reaction] = "Negative" ), [Customer ID] )

Neutral = 
VAR _a =
    SUMMARIZE (
        'Table',
        'Table'[Parent Topic],
        'Table'[Child Topic],
        'Table'[Customer ID],
        "Reaction",
            CALCULATE (
                MAX ( 'Table'[Reaction] ),
                FILTER ( 'Table', [Date] = MAX ( 'Table'[Date] ) )
            )
    )
RETURN
    COUNTX ( FILTER ( _a, [Reaction] = "Neutral" ), [Customer ID] )


Positive = 
VAR _a =
    SUMMARIZE (
        'Table',
        'Table'[Parent Topic],
        'Table'[Child Topic],
        'Table'[Customer ID],
        "Reaction",
            CALCULATE (
                MAX ( 'Table'[Reaction] ),
                FILTER ( 'Table', [Date] = MAX ( 'Table'[Date] ) )
            )
    )
RETURN
    COUNTX ( FILTER ( _a, [Reaction] = "Positive" ), [Customer ID] )

Average Shift = 
VAR _a =
    SUMMARIZE (
        'Table',
        'Table'[Parent Topic],
        'Table'[Child Topic],
        'Table'[Customer ID],
        'Table'[Reaction]
    )
VAR _b =
    SUMMARIZE (
        _a,
        'Table'[Parent Topic],
        'Table'[Child Topic],
        'Table'[Customer ID],
        "Shift",
            IF (
                COUNTX ( 'Table', [Reaction] ) > 1,
                CALCULATE (
                    MAX ( 'Table'[Reaction as number] ),
                    FILTER ( 'Table', [Call Name] = MAX ( 'Table'[Call Name] ) )
                )
                    - CALCULATE (
                        MIN ( 'Table'[Reaction as number] ),
                        FILTER ( 'Table', [Call Name] = MIN ( 'Table'[Call Name] ) )
                    )
            )
    )
RETURN
    AVERAGEX ( _b, [Shift] )

Final output:

vjianbolimsft_0-1688103190788.png

Best Regards,

Jianbo Li

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

You are amazing - have managed to put it into our model and worked perfectly - how you experts are able to do this is beyond me:-)  Thankyou so much!!!!!

Amazing - will give it a go and let you know how I do - can't believe how helpful people are in this community!

junglejimsvet
Helper I
Helper I

Apologies - I think I have made the post too big to get a response:(

 

Simplifying the question....   How to I use dax to only retrieve a field for the latest interaction with a customer?

 

e.g. I have seen the customer 3 times, I want to capture his satisfaction on the last visit... 

 

(ideally I need to segment this by product so if the customer bought 2 hoovers and an iron I would see the latest hoover satisfaction and the latest iron satisfaction)

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.