Forum Discussion
Achieve Distinct Count with Slicer
I have a table of student data which shows various changes to application records, including when an offer has been made. The dates are linked to a day of year number, and the rows are indexed for each applicant based on the application rank field.
| StudentId | ApplicationRank | DayNumber | Offer | LatestRecord |
| StudentA | 1 | 20 | 0 | FALSE |
| StudentA | 2 | 35 | 0 | FALSE |
| StudentA | 3 | 47 | 0 | FALSE |
| StudentA | 4 | 200 | 1 | FALSE |
| StudentA | 5 | 220 | 1 | FALSE |
| StudentA | 6 | 220 | 1 | TRUE |
| StudentA | 7 | 239 | 1 | FALSE |
| StudentB | 1 | 200 | 0 | FALSE |
| StudentB | 2 | 201 | 1 | TRUE |
| StudentB | 3 | 300 | 1 | FALSE |
| StudentB | 4 | 301 | 1 | FALSE |
The "LatestRecord" field is a calculated column as follows, where CurrentDayOfYearNumber returns the day number based on today's date:
9 Replies
- AnonymousNot applicable
Hi Anonymous
I suggest you to create an unrelated DayNumber Table by dax or what if parameter to create a slicer. Then calculate the distinct count of student ID by measure.
DayNumber Table:
DayNumber = GENERATESERIES(1,MAX('Table'[DayNumber]))Measure:
Distinct Count ID = VAR _SelectDayNumber = SELECTEDVALUE ( DayNumber[Value] ) RETURN CALCULATE ( DISTINCTCOUNT ( 'Table'[StudentId] ), FILTER ( ALL ( 'Table' ), 'Table'[DayNumber] <= _SelectDayNumber ) )Best Regards,
Rico ZhouIf this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
- AnonymousNot applicable
This has worked perfectly to get the count using a What If Parameter and the following measure:
Count =
VAR SelectedDay = SELECTEDVALUE( DateSelect[DateSelect])
RETURN
CALCULATE(
DISTINCTCOUNT(
'Table'[StudentId]
),
'Table'[Offer] = "1",
FILTER(
ALLSELECTED(
'Table'
),
'Table'[DayNumber] <= SelectedDay
&& 'Table'[ApplicationRank] <= MAX( 'Table'[ApplicationRank]
)
)
)
but I have an extra layer of complexity which it doesn't seem to solve - I've added the OfferType columns below to explain this:
StudentId
ApplicationRank
DayNumber
Offer
OfferTypeA
OfferTypeB
LatestRecord
StudentA
1
20
0
0
0
FALSE
StudentA
2
35
0
0
0
FALSE
StudentA
3
47
0
0
0
FALSE
StudentA
4
200
1
1
0
FALSE
StudentA
5
220
1
1
0
FALSE
StudentA
6
220
1
0
1
TRUE
StudentA
7
239
1
0
1
FALSE
StudentB
1
200
0
0
0
FALSE
StudentB
2
201
1
1
0
TRUE
StudentB
3
300
1
1
0
FALSE
StudentB
4
301
1
0
1
FALSE
So I would need the count as follows:
DayNumber 200 – Offer = 1; OfferTypeA = 1
DayNumber = 201 – Offer = 2; OfferTypeA = 2
DayNumber = 220 – Offer = 2; OfferTypeA = 1; OfferTypeB = 1
So by day number 301 Offer = 2; OfferTypeB = 2
The problem at the moment is that the count is including all those which have ever been an OfferTypeA even if they then switch to OfferTypeB, so DayNumber 301 Offer = 2; OfferTypeA = 2; OfferTypeB = 2
Is there any way to fix this within my measure?
Many thanks
- lbendlinSuper User
You should be able to implement this with a "What-If" parameter and adjusting your measure accordingly.
What happens when this process extends beyond one year? Or starts before Jan 1st?
- AnonymousNot applicable
There are further steps which ensure that all activity remains within a one year window, which is an academic year so runs from October each year, so this wouldn't cause an issue with the slicer - it should work across all years.
Can you elaborate on what you mean by "a "What-If" parameter and adjusting your measure accordingly " please?
- AnonymousNot applicable
Hello crains
Have you tried changing the condition to be based on selected date slicer?And adding filter for all values to filtter based on max selected date value
- AnonymousNot applicable
I can't seem to make a calculated column within the table which identifies the record to be selected based on the value in the slicer - is this possible?
- AnonymousNot applicable
Anonymous Hello,
You cannot create calculated column that changes dynamically, But you can create measure that uses selected value formula or in this case I would recomend using Max(date slicer value)