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

Calling all Data Engineers! Fabric Data Engineer (Exam DP-700) live sessions are back! Starting October 16th. Sign up.

Reply
jvanmeter
Frequent Visitor

Extracting First DN out of Distinguished Name

How Do I Extract the Text Found at the First DN= of the Distinguished Name?

 

Here is a Distinguished Name:

 

CN=Test,OU=Iowa,OU=Primary,DC=NA,DC=US,DC=COM

CN=Test,OU=Primary,DC=NA,DC=US,DC=COM

 

I want the output of the above to be NA

 

Essentially it would find the first occurnance from the left of DC= and return the text after that untill the next ,

 

This would give me the domain of each user.

 

Thank You Ahead of Time. 

1 ACCEPTED SOLUTION

OK, that means that some of your values don't have a DC= in them so you will want to use the "Not Found Value" parameter of FIND. https://msdn.microsoft.com/en-us/query-bi/dax/find-function-dax

 

So, something like:

 

Column = 
VAR myStart = FIND("DC=",[DN],,-99)
VAR myEnd = IF(myStart=-99,-99,FIND("DC=",[DN],myStart+3,-99))
RETURN IF(myEnd=-99,BLANK(),MID([DN],myStart+3,myEnd-myStart-4))

 

 



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!:
DAX For Humans

DAX is easy, CALCULATE makes DAX hard...

View solution in original post

4 REPLIES 4
Greg_Deckler
Community Champion
Community Champion

Column = 
VAR myStart = FIND("DC=",[DN])
VAR myEnd = FIND("DC=",[DN],myStart+3)
RETURN MID([DN],myStart+3,myEnd-myStart-4)


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!:
DAX For Humans

DAX is easy, CALCULATE makes DAX hard...

I get this error, "The search TExt Provided to function 'FIND' could not be found in the given text.

 

@Edit

 

It does not like FIND("DC=",[distinguishedName]) but does accept FIND("DC=",[distinguishedName],1,0) for whatever reason that is whats throwing the error

 

OK, that means that some of your values don't have a DC= in them so you will want to use the "Not Found Value" parameter of FIND. https://msdn.microsoft.com/en-us/query-bi/dax/find-function-dax

 

So, something like:

 

Column = 
VAR myStart = FIND("DC=",[DN],,-99)
VAR myEnd = IF(myStart=-99,-99,FIND("DC=",[DN],myStart+3,-99))
RETURN IF(myEnd=-99,BLANK(),MID([DN],myStart+3,myEnd-myStart-4))

 

 



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!:
DAX For Humans

DAX is easy, CALCULATE makes DAX hard...

That works Perfectly. Thank you.

Helpful resources

Announcements
FabCon Global Hackathon Carousel

FabCon Global Hackathon

Join the Fabric FabCon Global Hackathon—running virtually through Nov 3. Open to all skill levels. $10,000 in prizes!

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.

Top Solution Authors
Top Kudoed Authors