Forum Discussion
Count data based on criteria
Hello All,
I have two datasets.
The first one is a sheet with each possible article. Now I need to know the rows "Count" & "Distinctcount" based on criteria "ID". Count is counting each dataset based on the ID. Distinctcount is counting each distinct value based on ID. The row "Count" & "Distinctcount" is based on another data sheet (2. History). If there is no entry is should be displayed zero. Please see example in red below.
1. Overview of articles
| ID | Count | Distinctcount |
A-1 | 2 | 1 |
| A-2 | 2 | 1 |
| A-3 | 0 | 0 |
| B-1 | 3 | 2 |
| B-2 | 0 | 0 |
2. History
| ID | Colour |
| A-1 | Red |
| A-1 | Red |
| A-1 | Yellow |
| A-2 | White |
| B-1 | White |
| B-1 | Red |
| B-1 | Red |
| A-2 | White |
I really appreciate your help. Thank you very much in advance. SpartaBI Do you know the answer?
BR
Hi Anonymous
Are you wanting to total up the distinct count of colour for each id? If so you can use
Distinct count = SUMX ( VALUES('Overview of articles'[ID]), CALCULATE(DISTINCTCOUNT(History[Colour])) + 0)which will add up the individual distinct counts.
You can do this with a column. If you have the relationship ID - ID then
COUNT = CALCULATE(COUNT(History[Colour])) + 0and
Distinctcount = CALCULATE(DISTINCTCOUNT(History[Colour])) + 0should work again
3 Replies
- AntonioMSolution Sage
If you join the tables together on ID
Then write two measures
Count = COUNT(History[Colour]) + 0Distinctcount = DISTINCTCOUNT(History[Colour]) + 0Then you can create the table with Overview[Id], Count and Distinctcount. Is that what you're after?
- AnonymousNot applicable
Hi Antonio,
thank you very much for the quick reponse.
I need it as a extra coloum in the first table "Overview of articles". I tried the measure, but then there is another error. It wont summed up correct. I am not sure what the problem is, but building a sum from measure and coloums doesnt work correctly.Do you have a idea how to solve it as a extra coloumn?
- AntonioMSolution Sage
Hi Anonymous
Are you wanting to total up the distinct count of colour for each id? If so you can use
Distinct count = SUMX ( VALUES('Overview of articles'[ID]), CALCULATE(DISTINCTCOUNT(History[Colour])) + 0)which will add up the individual distinct counts.
You can do this with a column. If you have the relationship ID - ID then
COUNT = CALCULATE(COUNT(History[Colour])) + 0and
Distinctcount = CALCULATE(DISTINCTCOUNT(History[Colour])) + 0should work again