Forum Discussion
Word cloud multi-select intersection (AND instead of OR)
- 8 years ago
I used a Splitter function Splitter.SplitTextByWhitespace() to add a column splitting each sentence into words. Then I expanded this column into new rows.
Here is the query used in my dropbox link.
let Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WKslIVUhOLFEoKs0rVorVgQik5KejCuTmlxanIoRyK1FEYgE=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type text) meta [Serialized.Text = true]) in type table [Sentence = _t]), #"Changed Type" = Table.TransformColumnTypes(Source,{{"Sentence", type text}}), #"Duplicated Column" = Table.DuplicateColumn(#"Changed Type", "Sentence", "Sentence - Copy"), #"Lowercased Text" = Table.TransformColumns(#"Duplicated Column",{{"Sentence - Copy", Text.Lower, type text}}), #"Added Custom" = Table.AddColumn(#"Lowercased Text", "Word", each Splitter.SplitTextByWhitespace([#"Sentence - Copy"])), #"Expanded Word" = Table.ExpandListColumn(#"Added Custom", "Word"), #"Changed Type1" = Table.TransformColumnTypes(#"Expanded Word",{{"Word", type text}}), #"Removed Columns" = Table.RemoveColumns(#"Changed Type1",{"Sentence - Copy"}) in #"Removed Columns"With real text data, I imagine you would need to clean up the text in various ways and remove punctuation.
Hi ABmagic
You can do this creating an appropriate measure and using that to filter a 'sentences' visual.
See a dummy model here:
https://www.dropbox.com/s/499zocl05bk8bqk/Word%20cloud%20multi-select%20intersection.pbix?dl=0
I have a simple table called Sentences containing Sentence and Word columns.
| Sentence | Word |
| the cat runs | the |
| the cat runs | cat |
| the cat runs | runs |
| the dog runs | the |
| the dog runs | dog |
| the dog runs | runs |
| the mouse runs | the |
| the mouse runs | mouse |
| the mouse runs | runs |
| my mouse runs | my |
| my mouse runs | mouse |
| my mouse runs | runs |
I created these two measures:
Word Frequency =
COUNTROWS ( Sentences )
Sentence Count With All Words =
VAR WordsSelected =
ALLSELECTED ( Sentences[Word] )
RETURN
COUNTROWS (
FILTER (
VALUES ( Sentences[Sentence] ),
VAR WordsInSentence =
CALCULATETABLE ( VALUES ( Sentences[Word] ) )
RETURN
ISEMPTY ( EXCEPT ( WordsSelected, WordsInSentence ) )
)
)The Sentence Count With All Words measure checks whether the Words corresponding to a particular Sentence at least include all Words selected, and counts all Sentences meeting this condition.
Then I created a Word Cloud visual using Word & Word Frequency and a table visual simply containing the Sentence field.
On the table visual, I added a visual level filter Sentence Count With All Words > 0.
Then selecting multiple words filters the table visual appropriately.
This works with my simple data model, but could require tweaking depending how your tables are set up.
Hope that helps :)
Regards,
Owen
Any quick ways to create the "word" column? I have over 1300 rows of comments that I'm working with.
Thanks!
- OwenAuger8 years agoSuper User
I used a Splitter function Splitter.SplitTextByWhitespace() to add a column splitting each sentence into words. Then I expanded this column into new rows.
Here is the query used in my dropbox link.
let Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WKslIVUhOLFEoKs0rVorVgQik5KejCuTmlxanIoRyK1FEYgE=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type text) meta [Serialized.Text = true]) in type table [Sentence = _t]), #"Changed Type" = Table.TransformColumnTypes(Source,{{"Sentence", type text}}), #"Duplicated Column" = Table.DuplicateColumn(#"Changed Type", "Sentence", "Sentence - Copy"), #"Lowercased Text" = Table.TransformColumns(#"Duplicated Column",{{"Sentence - Copy", Text.Lower, type text}}), #"Added Custom" = Table.AddColumn(#"Lowercased Text", "Word", each Splitter.SplitTextByWhitespace([#"Sentence - Copy"])), #"Expanded Word" = Table.ExpandListColumn(#"Added Custom", "Word"), #"Changed Type1" = Table.TransformColumnTypes(#"Expanded Word",{{"Word", type text}}), #"Removed Columns" = Table.RemoveColumns(#"Changed Type1",{"Sentence - Copy"}) in #"Removed Columns"With real text data, I imagine you would need to clean up the text in various ways and remove punctuation.
- ABmagic8 years agoFrequent Visitor
Thanks for this! I'll have to give this a try sometime! Thanks!