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.
How to count the number of instance outside of the current context please ?
Use this Sales data
Record ID | Sales rep | Customer | Category | Product | Sales LY | Sales TY |
1 | Albert | Anne | TV | T42 | 20 | null |
2 | Albert | Anne | TV | T42 | 30 | null |
3 | Albert | Anne | TV | T62 | null | 50 |
4 | Albert | Anne | Radio | R100 | 55 | null |
5 | Albert | Anne | Kettle | K101 | 75 | null |
6 | Albert | Anne | Phone | P130 | null | 88 |
7 | Ben | Betty | Kettle | K315 | 87 | null |
8 | Ben | Bella | Kettle | K101 | null | 2 |
9 | Ben | Bella | Phone | P120 | null | 47 |
10 | Chris | Charlotte | Phone | P120 | 75 | null |
11 | Chris | Charlotte | Phone | P130 | 72 | null |
12 | Chris | Charlotte | Radio | R120 | null | null |
13 | Chris | Chloe | Radio | R100 | null | 94 |
14 | Chris | Camila | Radio | R101 | 44 | null |
15 | Chris | Camila | Radio | R500 | null | 31 |
16 | Chris | Camila | TV | T42 | 50 | 25 |
17 | Chris | Chloe | TV | T42 | null | 94 |
18 | Chris | Camila | Phone | P40 | null | 33 |
Create Measures
Total Sales LY = SUM(Sales[Sales LY])
Total Sales TY = SUM(Sales[Sales TY])
Status =
IF([Total Sales LY]>0 && [Total Sales TY]=0, "Lost",
IF([Total Sales LY]=0 && [Total Sales TY]>0, "New",
IF([Total Sales LY] > [Total Sales TY], "Reduced",
IF([Total Sales LY] < [Total Sales TY], "Grew",
"Same"))))
The Problem
2 reports are required.
For example:-
The reports should only count an instance of a customer once regardless of how many new or lost categories they have.
The New report should show by salesrep :-
The Lost report should show by salerep :-
How do you do that please?
Here is a screen print example using Count(Distinct) on Customer,
which does not produce the required results because
it aggregates at the Salesrep level instead of the Category level.
So no New and Loss status shows on then "Sales Rep Level" report
Solved! Go to Solution.
Thank you for your help, I have now solved it.
Please post any ideas on easier ways.
This is my solution ….
Add measures to get the Customer product Category level totals
Total Sales LY for Customer Category =
CALCULATE (
[Total Sales LY],
All (Sales),
VALUES(Sales[Customer]),
VALUES(Sales[Category])
)
Total Sales TY for Customer Category =
CALCULATE (
[Total Sales TY],
All (Sales),
VALUES(Sales[Customer]),
VALUES(Sales[Category])
)
Add measure to get the status at Customer product Category level
)
Then count the number of customers with a lost or new category
Customers with lost categories =
CALCULATE(DISTINCTCOUNT(Sales[Customer]),
FILTER(Sales,[Status at customer category level]="Lost"))
Customers with new categories =
CALCULATE(DISTINCTCOUNT(Sales[Customer]),
FILTER(Sales,[Status at customer category level]="New"))
Testing
See screen print
At record level Chris lost sales to Camila of product R101, but did sell some other Radios to Camila but not at much as last year. Note how the columns show New and Lost at record level but Reduced at Category level, as required.
Hi @speedramps ,
You could use DISTINCTCOUNT() function.
Here is my test file for your reference, but I think Chris has lost categories for 2 customers in the Lost table.
Thank you for your help, I have now solved it.
Please post any ideas on easier ways.
This is my solution ….
Add measures to get the Customer product Category level totals
Total Sales LY for Customer Category =
CALCULATE (
[Total Sales LY],
All (Sales),
VALUES(Sales[Customer]),
VALUES(Sales[Category])
)
Total Sales TY for Customer Category =
CALCULATE (
[Total Sales TY],
All (Sales),
VALUES(Sales[Customer]),
VALUES(Sales[Category])
)
Add measure to get the status at Customer product Category level
)
Then count the number of customers with a lost or new category
Customers with lost categories =
CALCULATE(DISTINCTCOUNT(Sales[Customer]),
FILTER(Sales,[Status at customer category level]="Lost"))
Customers with new categories =
CALCULATE(DISTINCTCOUNT(Sales[Customer]),
FILTER(Sales,[Status at customer category level]="New"))
Testing
See screen print
At record level Chris lost sales to Camila of product R101, but did sell some other Radios to Camila but not at much as last year. Note how the columns show New and Lost at record level but Reduced at Category level, as required.
When you are comparing 0 sales. Can you also handle null value
(ISBLANK(Sales[Sales LYTD]) OR Sales[Sales LYTD]) =0)
Thanks you, but I am not sure that helps with the above problem which uses measures?
I think the problem is about how to count the Status at a Category context level, whilst at Sales Rep level.
Many thanks
Here is example of the PBIX with the problem.
Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City
Check out the April 2024 Power BI update to learn about new features.
User | Count |
---|---|
114 | |
99 | |
82 | |
70 | |
60 |
User | Count |
---|---|
149 | |
114 | |
107 | |
89 | |
67 |