Forum Discussion
Looking for help with measures please
Hi, I’m looking for a few measures to get data from this table please. I need to find:
Row A – Total Numbers
Per customer ID, the number of customers whose score has Increased from the earliest score to the latest score by date
Per customer ID, the number of customers whose score has Decreased from the earliest score to the latest score by date
Per customer Id, the number of customers whose score has Score Remained Same / only had 1 score
Row B - % from the Row A results
Per customer ID, the % of the total customer ID’s who have Increased in score by date
Per customer ID, the % of the total customer ID’s who have Decreased in score by date
Per customer ID, the % of the total customer ID’s whose score has Score Remained Same / only had 1 score
Row C
The average amount of appointments the customer had per Increased Score
The average amount of appointments the customer had per Decreased Score
The average amount of appointments the customer had whose Score Score Remained Same / only had 1 score
If it could look something like the screenshot that would be amazing:. Thanks in advance!
| Date | Appointment Number | Customer ID | Customer name | Score |
| May-23 | 1 | A1 | Dave Davely | 45 |
| Jun-23 | 2 | A1 | Dave Davely | 33 |
| Jul-23 | 3 | A1 | Dave Davely | 24 |
| Aug-23 | 4 | A1 | Dave Davely | 34 |
| Sep-23 | 5 | A1 | Dave Davely | 55 |
| May-23 | 6 | B2 | John Johnson | 60 |
| Jun-23 | 7 | B2 | John Johnson | 50 |
| Jul-23 | 8 | B2 | John Johnson | 40 |
| May-23 | 9 | C3 | Evan Evans | 45 |
| Jun-23 | 10 | C3 | Evan Evans | 70 |
| Jul-23 | 11 | C3 | Evan Evans | 80 |
| Aug-23 | 12 | C3 | Evan Evans | 90 |
| May-23 | 13 | D4 | Adam Adams | 43 |
| Jun-23 | 14 | D4 | Adam Adams | 23 |
| Jul-23 | 15 | D4 | Adam Adams | 33 |
| Aug-23 | 16 | D4 | Adam Adams | 45 |
| May-23 | 17 | E5 | Ben Benson | 66 |
| Jun-23 | 18 | E5 | Ben Benson | 77 |
| Jul-23 | 19 | E5 | Ben Benson | 88 |
| Aug-23 | 20 | E5 | Ben Benson | 99 |
| May-23 | 21 | F6 | Carly Carlson | 50 |
| May-23 | 22 | G7 | Emily Elmson | 60 |
7 Replies
- Greg_Deckler
Community Champion
RichOB Let's see:
Total Icreased Measure = VAR __Table = ADDCOLUMNS( ADDCOLUMNS( DISTINCT( 'Table'[Customer ID] ), "__FirstDateScore", VAR __CustomerID = [Customer ID] VAR __FirstDate = MINX( FILTER( ALLSELECTED( 'Table'), [Customer ID] = __CustomerID ), [Date] ) VAR __FirstScore = MINX( FILTER( ALLSELECTED( 'Table'), [Customer ID] = __CustomerID && [Date] = __FirstDate ), [Score] ) RETURN __FirstScore, "__LastDateScore", VAR __CustomerID = [Customer ID] VAR __LastDate = MAXX( FILTER( ALLSELECTED( 'Table'), [Customer ID] = __CustomerID ), [Date] ) VAR __LastScore = MINX( FILTER( ALLSELECTED( 'Table'), [Customer ID] = __CustomerID && [Date] = __LastDate ), [Score] ) RETURN __LastScore ), "__Diff", [__LastDateScore] - [__FirstDateScore] ) VAR __Result = COUNTROWS( FILTER( __Table, [__Diff] > 0 ) ) RETURN __Result Total Percent Increased Measure = DIVIDE( [Total Icreased Measure], COUNTROWS(DISTINCT('Table'[Customer ID])), 0) Average Appointments Increased Measure = VAR __Table = ADDCOLUMNS( ADDCOLUMNS( DISTINCT( 'Table'[Customer ID] ), "__FirstDateScore", VAR __CustomerID = [Customer ID] VAR __FirstDate = MINX( FILTER( ALLSELECTED( 'Table'), [Customer ID] = __CustomerID ), [Date] ) VAR __FirstScore = MINX( FILTER( ALLSELECTED( 'Table'), [Customer ID] = __CustomerID && [Date] = __FirstDate ), [Score] ) RETURN __FirstScore, "__LastDateScore", VAR __CustomerID = [Customer ID] VAR __LastDate = MAXX( FILTER( ALLSELECTED( 'Table'), [Customer ID] = __CustomerID ), [Date] ) VAR __LastScore = MINX( FILTER( ALLSELECTED( 'Table'), [Customer ID] = __CustomerID && [Date] = __LastDate ), [Score] ) RETURN __LastScore ), "__Diff", [__LastDateScore] - [__FirstDateScore] ) VAR __IncreasedCustomers = DISTINCT( SELECTCOLUMNS( FILTER( __Table, [__Diff] > 0 ), "__ID", [Customer ID] ) ) VAR __Result = AVERAGEX( SUMMARIZE( FILTER( 'Table', [Customer ID] IN __IncreasedCustomers ), [Customer ID], "__Count", COUNTROWS('Table') ), [__Count] ) RETURN __Result- RichOB
Post Partisan
Hi Greg_Deckler thanks for your reply!
I've got the increased column correct, as well as the total clients decreased and avg appointments decreased, thank you.
I'm having trouble figuring out the:
- Total Percent Decreased measure
- One meeting /No Change Total, Percent, and Avg Appointment
I think the calculations for the above are what's stumping me, would you be able to help with those as well please?
Thanks
Rich
- Greg_Deckler
Community Champion
RichOB Was just working on this to add to the Quick Measures Gallery. The attached PBIX (below sig) has all of the requested measures I believe. It really just comes down to change the > sign to < or =
- RichOB
Post Partisan
Hi Greg_Deckler Thanks for your help with this, all looks great!
Sorry to be a pain but I now need to discount people who only had one score. Would you be so kind to change the "One Score/No Change" to "No Change" for people who had 2 or more scores with no change in their first to last scores.
Then a measure (or way) to rule out scores for people who only had 1 score, please?
Sorry again and thank you!!
Rich
Would you be so kind to change the combined "One Meeting/No Change" measures to have just the No Change in score please?
Thanks so much for your help
Rich
- Greg_Deckler
Community Champion
RichOB That's a pretty trivial change. The updated pbix has those measures in in. Basically only one line has to change:
Total No Change Measure 2 = VAR __Table = ADDCOLUMNS( ADDCOLUMNS( FILTER( SUMMARIZE( 'Table', [Customer ID], "__Count", COUNTROWS( 'Table' ) ), [__Count] > 1 ), "__FirstDateScore", VAR __CustomerID = [Customer ID] VAR __FirstDate = MINX( FILTER( ALLSELECTED( 'Table'), [Customer ID] = __CustomerID ), [Date] ) VAR __FirstScore = MINX( FILTER( ALLSELECTED( 'Table'), [Customer ID] = __CustomerID && [Date] = __FirstDate ), [Score] ) RETURN __FirstScore, "__LastDateScore", VAR __CustomerID = [Customer ID] VAR __LastDate = MAXX( FILTER( ALLSELECTED( 'Table'), [Customer ID] = __CustomerID ), [Date] ) VAR __LastScore = MINX( FILTER( ALLSELECTED( 'Table'), [Customer ID] = __CustomerID && [Date] = __LastDate ), [Score] ) RETURN __LastScore ), "__Diff", [__LastDateScore] - [__FirstDateScore] ) VAR __Result = COUNTROWS( FILTER( __Table, [__Diff] = 0 ) ) RETURN __ResultThis is the line that excludes customers with only 1 row.
FILTER( SUMMARIZE( 'Table', [Customer ID], "__Count", COUNTROWS( 'Table' ) ), [__Count] > 1 ),
- RichOB
Post Partisan
Greg_Deckler Ah right that makes sense with the filter thank you. Something isn't right when I replicate the measures to my real-life scenario.
(all personal info removed) - Score Test - Google Sheets
The total number of people is correct but the percentages don't add up to 100 which makes me think they're not taking into consideration every result or date? This is what I'm getting:
If you wouldn't mind having a look I'd be very grateful.
Thanks
Rich
- Greg_Deckler
Community Champion
RichOB I suspect it is because you are counting the people with only 1 appointment in your total. So to avoid that, probably this:
Total Percent Increased Measure = DIVIDE( [Total Icreased Measure], COUNTROWS(FILTER( SUMMARIZE( 'Table', [Customer ID], "__Count", COUNTROWS( 'Table' ) ), [__Count] > 1 )), 0 )