Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
6 years ago

Modification to Time intelligence measure

Hi all,

I'm hoping someone can help with a modification I need to make to some existing time time intelligence measures.

I originally had a large data table (10,000+ rows) of information relating to customer support documents, and how often each document has been used in a support scenario. Rows included the customer name for each document, the RefNum for the support ticket that resulted from each support scenario (RefNum did not contain unique numbers, because a customer support document might have been used in multiple different support scenarios. So each row in the table represented a single support scenario), the Full Name of the support analyst who handled the case, the timestamp 'DateActivityCreated' of when the case was generated, and the title of the support document. Example below:

 

TenantRefNumFull NameDateActivityCreatedDoc Title
Google9193141Jenny Jenson2/12/2019 14:18Google - Pin@store Error - Card could not be written or read
Alphabet9193142Jenny Jenson14/01/2020 14:16Alphabet - Application - Adobe products license issue
Apple9193144Jenny Jenson2/12/2019 14:18Apple - Password Reset - NPE
Google9193145Jenny Jenson2/12/2019 14:19Google - Postlink - Freezing in Parcel Value Field
IBM9193147Jimmy James2/12/2019 14:17IBM - Network (LAN) Account Unlock
IBM9193147Jimmy James2/12/2019 14:18IBM - Network (LAN) Account Unlock
IBM9193147Jimmy James2/12/2019 14:18IBM - Network (LAN) Account Unlock
IBM9193147Cameron Camson2/12/2019 14:16IBM - Network (LAN) Account Unlock
IBM9193147Jenny Jenson14/01/2020 14:16IBM - Network (LAN) Account Unlock
IBM9193147Jimmy James14/01/2020 14:16IBM - Network (LAN) Account Unlock
IBM9193147Jimmy James14/01/2020 14:16IBM - Network (LAN) Account Unlock
IBM9193147Jimmy James14/01/2020 14:16IBM - Network (LAN) Account Unlock
IBM9193147Jimmy James14/01/2020 14:16IBM - Network (LAN) Account Unlock
ICC9193151Cameron Camson2/12/2019 14:19ICC - eShip - Child Accounts
Alphabet9193152Cameron Camson2/12/2019 14:18Alphabet - JDE - Unable to save the report because the network drive is missing
Samsung9193154Jackie Jackson14/01/2020 14:16Samsung - New user request
Samsung9193154Jackie Jackson2/12/2019 14:18Samsung - New user request
Samsung9193154Jackie Jackson2/12/2019 14:18Samsung - New user request
Samsung9193154Jackie Jackson2/12/2019 14:18Samsung - New user request
Samsung9193154Jackie Jackson2/12/2019 14:18Samsung - New user request
Samsung9193154Jackie Jackson2/12/2019 14:18Samsung - New user request
Google9193168Jackie Jackson2/12/2019 14:22Google - NZTA TXN Error - 953 timed out waiting for response from CDI
Blackberry Limited9193172Jimmy James2/12/2019 14:21Blackberry Limited – Email – Outlook Issues (Generic)
Blackberry Limited9193172Jimmy James14/01/2020 14:16Blackberry Limited – Email – Outlook Issues (Generic)
Blackberry Limited9193172Jimmy James2/12/2019 14:21Blackberry Limited – Email – Outlook Issues (Generic)
Samsung9193174Jimmy James2/12/2019 14:21Samsung - Disable user request
ICC9193175Jimmy James2/12/2019 14:22ICC - eShip - Printer Issues (newly onboarded user)
Alphabet9193177Jenny Jenson2/12/2019 14:21Alphabet - Forcepoint - Email Releases
Alphabet9193177Jenny Jenson14/01/2020 14:16

Alphabet - Forcepoint - Email Releases

 

I wanted to be able to create a summary table, that showed a unique list of the support documents, the customer name for each document, and some measures. Here's an example (the columns in bold are the ones I needed):

 

CustomerDocTitleCount Links (Last Month)Count Links (Last Month -2)% Change From (Last Month -2)Rank (Last Month)Rank (Last Month -2)Rank Change (From Last Month-2 to Last Month)
IBMIBM - Network (LAN) Account Unlock5425%12-1
AlphabetAlphabet - Application - Adobe products license issue10New2N/A2
SamsungSamsung - New user request15-80%21-1
Blackberry LimitedBlackberry Limited – Email – Outlook Issues (Generic)12-50%23-1
AlphabetAlphabet - Forcepoint - Email Releases110%24-2
GoogleGoogle - Pin@store Error - Card could not be written or read01-100%N/A4-4
AppleApple - Password Reset - NPE01-100%N/A4-4
GoogleGoogle - Postlink - Freezing in Parcel Value Field01-100%N/A4-4
ICCICC - eShip - Child Accounts01-100%N/A4-4
AlphabetAlphabet - JDE - Unable to save the report because the network drive is missing01-100%N/A4-4
GoogleGoogle - NZTA TXN Error - 953 timed out waiting for response from CDI01-100%N/A4-4
SamsungSamsung - Disable user request01-100%N/A4-4
ICCICC - eShip - Printer Issues (newly onboarded user)01-100%N/A4-4

 

 

And here's how the fields would intended to be calculated:

1) Count Links (Last Month) = count of how many times each support document has been used (based on how many rows it appears in, in the month preceeding whatever month it is currently)
2) Count Links (Last Month -2) = count of how many times each support document has been used (based on how many rows it appears in, in the month BEFORE the month preceeding whatever month it is currently)
3) % Change From (Last Month -2) = This would be calculated as (#3-#2)/#2, except where #2 = 0, in which case the result should be "New"
4) Rank (Last Month) = for the top 20 support documents only, this will show a ranking based on #1
5) Rank (Last Month -2) = for the top 20 support documents only, this will show a ranking based on #1 (in the month BEFORE the month preceeding whatever month it is currently)
6) Rank Change (From Last Month-2 to Last Month) = the difference between #4 and #5

 

A very kind person put together the below for me, which worked a treat (they used "Date(2020,1,1)" as the current date for testing, which I replaced Now() 😞

 

 

 

 

Summary = 
SUMMARIZE(
          'Table',
          'Table'[Tenant],
          'Table'[Doc Title],
          "Count Links (Last Month)",
          CALCULATE(
                   COUNTROWS('Table'),
                   FILTER(
                        'Table',
                        AND(
                            'Table'[DateActivityCreated]<=EOMONTH(DATE(2020,2,1),-1),
                            'Table'[DateActivityCreated]>=EOMONTH(DATE(2020,2,1),-2)+1
                        )
                   )
          ),
          "Count Links (Last Month -2)",
          CALCULATE(
                   COUNTROWS('Table'),
                   FILTER(
                        'Table',
                        AND(
                            'Table'[DateActivityCreated]<=EOMONTH(DATE(2020,2,1),-2),
                            'Table'[DateActivityCreated]>=EOMONTH(DATE(2020,2,1),-3)+1
                        )
                   )
          )

)

 

 

 

And here are the measures:

 

 

% Change From (Last Month -2) = 
var _lastmonth2 = SUM(Summary[Count Links (Last Month -2)])
var _lastmonth = SUM(Summary[Count Links (Last Month)])
return
IF(
    _lastmonth2 <> 0,
    SUMX(
         Summary,
         (_lastmonth-Summary[Count Links (Last Month -2)])/Summary[Count Links (Last Month -2)]
    ),
    "New"
)

Rank (Last Month) = 
RANKX(
    ALLSELECTED(Summary),
    CALCULATE(SUM(Summary[Count Links (Last Month)])),
    ,
    DESC,
    Dense
)

Rank (Last Month -2) = 
RANKX(
      ALLSELECTED(Summary),
      CALCULATE(SUM(Summary[Count Links (Last Month -2)])),
      ,
      DESC,
      Dense
)

Rank Change (From Last Month-2 to Last Month) = [Rank (Last Month)]-[Rank (Last Month -2)]

 

 

 

The kind person then advised me to go to the table level filter and configure both the values of Rank(Last Month) and Rank(Last Month - 2) with 'is less than or equal to 20':

 

 

This all works well, but I'm finding with my live data set that the 'Rank (Last Month)' often returns a duplicate value, because sometimes the 'Count Links (Last Month)' or 'Count Links (Last Month -2)' calculated columns are returning duplicate values in those instances:

 

 

What I'd like is to be able to do is have a completely (as much as I can) unique 'Rank (Last Month)' field, by adding the followig logic (in bold):

Rank (Last Month) = for the top 20 support documents only, this will show a ranking based on the following rules:

1) Count of how many times each support document has been used (based on how many rows it appears in, in the month preceeding whatever month it is currently)
2) Then, count of how many times each support document has been used (based on how many rows it appears in, in the month preceeding whatever month it is currently, -2) (i.e. the previous month)
3) Then, '% Change (From Month Prior)
4) Then, base the ranking on which Doc Title appears first in the alphabetised list.

I'd really appreciate any assistance here!

4 Replies

  • kentyler's avatar
    kentyler
    Solution Sage

    this problem is generic when you use ranking... there seems to also be a generic solution

    1) take the number you want to rank

    2) multiply it by 1000

    3) add the result of calling  RANDBETWEEN(0,999)
    the extra three digits should mean that you will no longer have duplicate numbers in the column you are trying to rank

    so your code

    RANKX(
          ALLSELECTED(Summary),
          CALCULATE(SUM(Summary[Count Links (Last Month -2)])),

    might change the expression inside the SUM

    to be

    (Summary[Count Links (Last month -1)] * 1000) + RANDBETWEEN(0,999)

     

    I'm a personal Power Bi Trainer I learn something every time I answer a question

    The Golden Rules for Power BI

    1. Use a Calendar table. A custom Date tables is preferable to using the automatic date/time handling capabilities of Power BI. https://www.youtube.com/watch?v=FxiAYGbCfAQ
    2. Build your data model as a Star Schema. Creating a star schema in Power BI is the best practice to improve performance and more importantly, to ensure accurate results! https://www.youtube.com/watch?v=1Kilya6aUQw
    3. Use a small set up sample data when developing. When building your measures and calculated columns always use a small amount of sample data so that it will be easier to confirm that you are getting the right numbers.
    4. Store all your intermediate calculations in VARs when you’re writing measures. You can return these intermediate VARs instead of your final result  to check on your steps along the way.
    • Anonymous's avatar
      Anonymous
      Not applicable

      Thanks for the respons kentyler - I'm getting the following error, am I doing something obviously wrong?

       

      • kentyler's avatar
        kentyler
        Solution Sage

        You might have to do the multiplication in a calculated column in the table.