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

Find everything you need to get certified on Fabric—skills challenges, live sessions, exam prep, role guidance, and more. Get started

Reply
ABmagic
Frequent Visitor

Word cloud multi-select intersection (AND instead of OR)

Hello,

 

I've been playing with the Word Cloud visualization and I'm wondering whether there's a setting that allows you to change the logic that's employed when selecting multiple words in the visualization. For example, if I saw the word "phone" and "store", I may want to see all the comments that contain both of those words. However, right now, it is set up as an OR where it will pull in comments that contain either "phone" or "store".

 

This may be the default for most visualizations in Power BI, but wonder if there's a way to customize the logic that is being used.

 

 

Thanks!

1 ACCEPTED SOLUTION

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.


Owen Auger
Did I answer your question? Mark my post as a solution!
Blog
Twitter
LinkedIn

View solution in original post

7 REPLIES 7
spmvoss
Regular Visitor

I realise this is an old topic, but it is almost exactly what I am looking for as well.

 

I have a large dataset with work hours logging with descriptions for each entry. I have then used an external algorithm to extract keywords, which are then added in a comma sepparated list, see the table below. I have a word cloud visual with Keywords as the category and Hours as the values.

 

Now, the problem I have with the proposed solution is that this would blow up my dataset, considering the average number of keywords is 6/7. Would anyone know a clever way of solving this without having a lot of duplicate lines? I thought of using the FIND() function, but my problem is that the ALLSELECTED() function will return [Updating, Requirements, Document] instead of just Updating when we select that word.

 

DateProjectHoursDescriptionKeywords
20-07-2020Project X2.5Updating the Requirements Document[Updating, Requirements, Document]
OwenAuger
Super User
Super User

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.

 

SentenceWord
the cat runsthe
the cat runscat
the cat runsruns
the dog runsthe
the dog runsdog
the dog runsruns
the mouse runsthe
the mouse runsmouse
the mouse runsruns
my mouse runsmy
my mouse runsmouse
my mouse runsruns

 

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


Owen Auger
Did I answer your question? Mark my post as a solution!
Blog
Twitter
LinkedIn

Any quick ways to create the "word" column? I have over 1300 rows of comments that I'm working with.

 

Thanks!

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.


Owen Auger
Did I answer your question? Mark my post as a solution!
Blog
Twitter
LinkedIn

Thanks for this! I'll have to give this a try sometime! Thanks!

v-yuezhe-msft
Microsoft Employee
Microsoft Employee

@ABmagic,

I am afraid that there is no method to customize the logic as you describe in Word Cloud custom visual, regarding to this issue, you can submit a feature request in Power BI ideas forum.

Regards,
Lydia

Community Support Team _ Lydia Zhang
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Is this the same for all visualizations within Power BI?

 

Thanks!

Helpful resources

Announcements
September Hackathon Carousel

Microsoft Fabric & AI Learning Hackathon

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

Top Solution Authors