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

Grow your Fabric skills and prepare for the DP-600 certification exam by completing the latest Microsoft Fabric challenge.

Reply
Joe_Sauer
New Member

Request Help on PQ Prob: De-concatenate Name data, Assoc w/YN data & Calc Percent Yes by Name

In my Source query, I have concatenated Name data that is associated with separate YesNo data, that looks like the first table below. The actual set of names is a long list of ~100 people (in 'Last Name, First Name' format). Sometimes there is a single name in the Name cell; sometimes there are multiple names in the Name cell. There is no limit to the number of multiple names in the Name cell, but it is unlikely to ever be more than five. If there are multiple names in the Name cell, then the names are always separated by a semi-colon as shown in the table below.

 

YesNo        Name

YesCat
NoDog
YesBat
YesHog
NoPig
YesOx
NoFox
YesLamb
YesCow
NoAnt
NoCat;Dog
YesBat;Hog
YesPig;Ox
NoFox;Lamb
NoCow;Ant
YesCat;Dog;Bat
YesHog;Pig;Ox
NoFox;Lamb;Cow
YesLamb;Cow;Ant
YesCat;Dog;Bat;Hog
NoHog;Pig;Ox;Fox
YesFox;Lamb;Cow;Ant
YesCat;Bat;Pig
NoDog;Hog;Ox
YesBat;Pig;Fox
NoHog;Ox;Lamb
YesAnt;Lamb;Ox
NoCow;Fox;Pig
NoDog;Bat
YesHog;Pig
YesOx;Fox
NoLamb;Cow
YesCow;Ant
NoCat;Ant
YesDog;Cow
YesBat;Lamb
NoHog;Fox
YesPig;Ox

 

In PQ, I want to de-concatenate the name data, but continue to associate each de-concatenated name with that row's YN data. Then, calculate the total number of Yes's for each unique Name, and calculate the total number of entries for each unique Name. Then, calculate the percent of Yes's for each unique Name. I could probably do the last part as a 'Measure' in Power BI.

 

The final result of the above data would end up as follows:

 

Name   Yes's   Total  Pct_Yes

Cat4666.7%
Dog3742.9%
Bat7887.5%
Hog5955.6%
Pig6966.7%
Ox6966.7%
Fox3933.3%
Lamb5955.6%
Cow5955.6%
Ant4757.1%

 

Can anyone help me get started on this?? ... Thanks!

1 ACCEPTED SOLUTION
lbendlin
Super User
Super User

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("fZGxDsIwDET/JXP/4CYoQh0QZUVRhyIhxAAZQGo/n7ipY5sERsfOPd/Ze3e+vlzj2vHthsa7Y4jFLtyWIrW2aytV3dpbBk93PdjP0tmHWXUO4+OiyjZMMrl5KnJcAwUdnXmJUHyhkAFJJUxg2WyPdFF4wS818JLiAH91YZIRadgotH5FjIQ4Vb4FKfOOEgqps3RG9iqKNBoRiadNEpsWKUjVfMyJLbOSlPaVb2qNEsl+IkP2hsS2yfGlhg8=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [YesNo = _t, Name = _t]),
    #"Split Column by Delimiter" = Table.ExpandListColumn(Table.TransformColumns(Source, {{"Name", Splitter.SplitTextByDelimiter(";", QuoteStyle.Csv), let itemType = (type nullable text) meta [Serialized.Text = true] in type {itemType}}}), "Name")
in
    #"Split Column by Delimiter"

How to use this code: Create a new Blank Query. Click on "Advanced Editor". Replace the code in the window with the code provided here. Click "Done". Once you examined the code, replace the Source step with your own source.

 

lbendlin_0-1715473866512.png

 

 

View solution in original post

3 REPLIES 3
lbendlin
Super User
Super User

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("fZGxDsIwDET/JXP/4CYoQh0QZUVRhyIhxAAZQGo/n7ipY5sERsfOPd/Ze3e+vlzj2vHthsa7Y4jFLtyWIrW2aytV3dpbBk93PdjP0tmHWXUO4+OiyjZMMrl5KnJcAwUdnXmJUHyhkAFJJUxg2WyPdFF4wS818JLiAH91YZIRadgotH5FjIQ4Vb4FKfOOEgqps3RG9iqKNBoRiadNEpsWKUjVfMyJLbOSlPaVb2qNEsl+IkP2hsS2yfGlhg8=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [YesNo = _t, Name = _t]),
    #"Split Column by Delimiter" = Table.ExpandListColumn(Table.TransformColumns(Source, {{"Name", Splitter.SplitTextByDelimiter(";", QuoteStyle.Csv), let itemType = (type nullable text) meta [Serialized.Text = true] in type {itemType}}}), "Name")
in
    #"Split Column by Delimiter"

How to use this code: Create a new Blank Query. Click on "Advanced Editor". Replace the code in the window with the code provided here. Click "Done". Once you examined the code, replace the Source step with your own source.

 

lbendlin_0-1715473866512.png

 

 

Thanks again lbendlin. I did integrate your solution and it worked 100% great. I don't understand exactly how it works, but it certainly did work. Thank you again for your very smart and quick help!

Thank you lbendlin. I will check out your solution later today or tomorrow. I will reply on the results.  Thanks for taking the time to help me.

Helpful resources

Announcements
RTI Forums Carousel3

New forum boards available in Real-Time Intelligence.

Ask questions in Eventhouse and KQL, Eventstream, and Reflex.

MayPowerBICarousel1

Power BI Monthly Update - May 2024

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

Top Solution Authors
Top Kudoed Authors