Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Get certified in Microsoft Fabric—for free! For a limited time, the Microsoft Fabric Community team will be offering free DP-600 exam vouchers. Prepare now

Reply
NumeroENAP
Helper III
Helper III

COUNT DISTINCT users ID, but only select their last result

Hi, 

 

I have someting of the kind :

 

UserIDNameDT_EVALConformity
Markov67Andrei Markov2020-08-10conform
Markov67Andrei Markov2020-08-08not conform
Plekanec14Thomas Plekanec2020-08-10not conform

 

I want my measure to return me : 2

 

Reason : I only want the last evaluation of every user. 

 

Thanks

1 ACCEPTED SOLUTION

In the end, I went with a non-performing option, but it works great. 

 

First of all, I created a calculated column : 

LAST_EVAL_DT = VAR LastID = RES[ID]
RETURN
MAXX(
FILTER( ALL('RES') , 'RES'[ID] = LastID) , 
'RES'[DT_EVAL])
 
After that, I created a column that I could filter easily with a COUNTROWS :
QC = IF (RES[DT_EVAL] = RES[LAST_EVAL_DT] , 1 , BLANK() )
 
Thank you all for your efforts.

View solution in original post

6 REPLIES 6
Greg_Deckler
Super User
Super User

@NumeroENAP - Perhaps use MAX to get the greatest date in the table and then FILTER down to that date, use DISTINCT and COUNTROWS, so like:

 

Measure = COUNTROWS(DISTINCT(FILTER('Table',[Date] = MAX('Table'[Date])))



Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
Power BI Cookbook Third Edition (Color)

DAX is easy, CALCULATE makes DAX hard...

Ok, it's nice, and it's defenitely the closest I've been from the solution, but, it's not exactly what I need.
 
By exemple, if I need to group it by conformity :
 
ConformityDistinct User
Conform1
Not conform2

 

But, with what you gave me, even if it gives me a table with what I need (raw), but I can't group it the way I want.

 

Am I clear enough?

 

Thanks!

@NumeroENAP - Wait, now I am confused, where did conform/not comform come from? Perhaps we should back-up. Please first check if your issue is a common issue listed here: https://community.powerbi.com/t5/Community-Blog/Before-You-Post-Read-This/ba-p/1116882

Also, please see this post regarding How to Get Your Question Answered Quickly: https://community.powerbi.com/t5/Community-Blog/How-to-Get-Your-Question-Answered-Quickly/ba-p/38490

The most important parts are:
1. Sample data as text, use the table tool in the editing bar
2. Expected output from sample data
3. Explanation in words of how to get from 1. to 2.



Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
Power BI Cookbook Third Edition (Color)

DAX is easy, CALCULATE makes DAX hard...

I need to have a measure that tells me exactly :

  • How many employees have a «conform» or «not conform» evaluation at their last evaluation ;
  • I also need that measure to be flexible, so I can use it in others visualisation, with other columns of the same table.  

 

UserIDNameDT_EVALConformity
Markov67Andrei Markov2020-08-10Conform
Markov67Andrei Markov2020-08-08Not conform
Plekanec14Thomas Plekanec2020-08-10Not conform

 

Thanks!

Anonymous
Not applicable

// You have to have a Calendar table
// that's DISCONNECTED from the T table.
// Now, this is a measure that for a
// selected period of time from Calendar
// tells you the number of 'Conform'
// emps at their last evaluation BEFORE OR ON
// the last day of the selected period.
// I assume an employee is fully identified
// by UserID and that each employee can only
// have 1 entry on any specific day. This
// measure does fully respond to slicers, so
// be careful to correctly interpret the results.

[# Conform Emps] =
var __lastVisibleDate = MAX( Calendar[Date] )
var __empsWithConformAsLastEval =
	FILTER(
		VALUES( T[UserID] ),
		var __latestRecordForUser =
			CALCULATETABLE(
				TOPN(1,
					filter(
						T,
						T[DT_EVAL] <= __lastVisibleDate
					),
					T[DT_EVAL],
					DESC
				)
			)
		var __conformityIsConform =
			NOT ISEMPTY(
				FILTER(
					__latestRecordForUser,
					T[Conformity] = "conform"
				)
			)
		return
			__conformityIsConform
	)
return
	COUNTROWS( __empsWithConformAsLastEval )

In the end, I went with a non-performing option, but it works great. 

 

First of all, I created a calculated column : 

LAST_EVAL_DT = VAR LastID = RES[ID]
RETURN
MAXX(
FILTER( ALL('RES') , 'RES'[ID] = LastID) , 
'RES'[DT_EVAL])
 
After that, I created a column that I could filter easily with a COUNTROWS :
QC = IF (RES[DT_EVAL] = RES[LAST_EVAL_DT] , 1 , BLANK() )
 
Thank you all for your efforts.

Helpful resources

Announcements
OCT PBI Update Carousel

Power BI Monthly Update - October 2024

Check out the October 2024 Power BI update to learn about new features.

September Hackathon Carousel

Microsoft Fabric & AI Learning Hackathon

Learn from experts, get hands-on experience, and win awesome prizes.

October NL Carousel

Fabric Community Update - October 2024

Find out what's new and trending in the Fabric Community.

Top Kudoed Authors