Forum Discussion
PatrickDpladis
1 year agoNew Member
Trying to Get OU information
I have a spreadsheet with user and their full distinguished name, and I have an Excel query that shows me the "top level OU" for each user. for example a user can be called: CN=Firstname Surname,O...
- 1 year ago
Paste the code below into the advanced editor to examine one way of doing what you asked:
let Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WcvazdcssKi7JS8xNVQguLQLROv6htj6pZak5hnCWEZxlrOPibOsb6eLv6+jpB2I7+/sqxcYCAA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Column1 = _t]), #"Changed Type" = Table.TransformColumnTypes(Source,{{"Column1", type text}}), #"Add OU" = Table.AddColumn(#"Changed Type", "OU", (r)=> Text.AfterDelimiter( List.Last( List.Select(Text.Split(r[Column1],","), each Text.StartsWith(_,"OU"))), "="), type text) in #"Add OU" - 1 year ago
Easy enough,
= Table.AddColumn(#"Changed Type", "Top", each Text.BetweenDelimiters([Usr], "OU=", ",", {0, RelativePosition.FromEnd}, 0))I guess py script would be more performant with large dataset,
let Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WcvazdcssKi7JS8xNVQguLQLROv6htj6pZak5hnCWEZxlrOPibOsb6eLv6+jpB2I7+/sqxeqQZRKMZUKxmdj0xwIA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Usr = _t]), #"Run Python script" = Python.Execute("import numpy as np#(lf)dataset['OU'] = np.vectorize(lambda ele: ele[-1])(dataset['Usr'].str.findall(r'(?<=OU=)[^,]+'))",[dataset=Source]), dataset = #"Run Python script"{[Name="dataset"]}[Value] in dataset - Anonymous1 year ago
Hi,
Thanks for the solution ThxAlot and ronrsnfld offered, and i want to offer different solutions for user to refert to.
hello PatrickDpladis , you cna refer to th following code.
let Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WcvazdcssKi7JS8xNVQguLQLROv6htj6pZak5hnCWEZxlrOPibOsb6eLv6+jpB2I7+/sqxcYCAA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Column1 = _t]), #"Changed Type" = Table.TransformColumnTypes(Source,{{"Column1", type text}}), #"Added Custom" = Table.AddColumn(#"Changed Type", "Custom", each let a=Text.PositionOf([Column1],"OU"), b=Text.PositionOf([Column1],"DC"), c=Text.Middle([Column1],a,b-1-a), d=List.Max(Text.Split(Text.Replace(c,"OU=",""),",")) in d) in #"Added Custom"Output
Best Regards!
Yolo Zhu
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
ronrsnfld
1 year agoSuper User
Paste the code below into the advanced editor to examine one way of doing what you asked:
let
Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WcvazdcssKi7JS8xNVQguLQLROv6htj6pZak5hnCWEZxlrOPibOsb6eLv6+jpB2I7+/sqxcYCAA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Column1 = _t]),
#"Changed Type" = Table.TransformColumnTypes(Source,{{"Column1", type text}}),
#"Add OU" = Table.AddColumn(#"Changed Type", "OU", (r)=>
Text.AfterDelimiter(
List.Last(
List.Select(Text.Split(r[Column1],","),
each Text.StartsWith(_,"OU"))),
"="), type text)
in
#"Add OU"