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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
dsdesrosiers
Helper I
Helper I

Return a list and count of related items

Greetings all -

I am trying to solve what seems like a common question but no luck. Perhaps I am just googling poorly but in any case, I am ready to try this forum which has always worked well for me. I want to find phrases related to a selected phrase out of a table. In my case, these are product features for my company but I cannot use those terms here so I am using food terms. 

I have data similar to the below in a table... I also have a dimention table with a list of unique values found on the Phrase column... (not shown but you get the idea I am sure). The tables are related One-to-Many

IDPhrase
1avocado
1peanut
2avocado
3chocolate
3eggs
3milk
3peanut
4bread
4chocolate
4eggs
4peanut


What I would like is a slicer on the Unique list ...and when a value is selected for these results to show a list of related phrases and counts of those phrases. For example, if I were to select Peanut, the results should be this:

bread1
chocolate2
eggs2
milk1
avocado1


Essentially, I would like to know how product features correlate to each other across IDs. 

Thanks in advance

1 ACCEPTED SOLUTION

The first measure is the problem, my fault: This should work:

Measure =
VAR _selectphrase = SELECTEDVALUE(Dim[Phrase])
VAR _id= SUMMARIZE(FILTER(ALL('Fact'),'Fact'[Phrase]=_selectphrase),'Fact'[ID])
RETURN countx(FILTER('Fact','Fact'[ID] IN _id),'Fact'[Phrase])




Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




View solution in original post

11 REPLIES 11
dsdesrosiers
Helper I
Helper I

Thank you so, so much. This will really be useful for this project and I am sure for others as well. I really appreciate you sticking it out with me!

andhiii079845
Super User
Super User

Thank you for your further explanation. Now in understand it.

You have to create a second table for the slicer. 

andhiii079845_0-1679062564505.png

And create a measure:

Measure = 

VAR _selectphrase = SELECTEDVALUE(Dim[Phrase])
VAR _id= SUMMARIZE(FILTER(ALLSELECTED('Fact'),'Fact'[Phrase]=_selectphrase),'Fact'[ID])
RETURN CALCULATE(count('Fact'[Phrase]),FILTER('Fact','Fact'[ID] IN _id))
The result: the phrase column is from the fact table!
Bildschirmfoto 2023-03-17 um 15.18.08.png

You can also filter out "peanut" this will be second measure for the filter plane of the matrix.

 
Measure 2 = 
VAR _select = SELECTEDVALUE(Dim[Phrase])
RETURN
if(SELECTEDVALUE('Fact'[Phrase])<>_select,1,0)
To show the result of the measure:
Bildschirmfoto 2023-03-17 um 15.20.21.png

You do not have to use this Measure 2 in the matrix. It is only for the visualization of the result. 

andhiii079845_0-1679062895966.png

 





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




This is brilliant - thank you so much! Exactly (almost! what I needed...). Thanks as well for the screen shots, the one showing that the two tables do NOT have a relationship is key... One issue is the second measure. Using the data we've been using... if I pick Chocolate the measures are exactly what I'd expect... 

dsdesrosiers_0-1679075837698.png

but when I apply Measure2 to be greater than or equal to 1, Chocolate is removed but so are all the other counts... I think it's because my selected value search term is gone... the reason I care is that if I can show the counts for all BUT the search term I can show the percent of the column as well as the counts which I think may be useful. 

dsdesrosiers_1-1679076006341.png

 

Can you please check from which table is the slicer(should be dim!) and from which table is the column in the matrix(should be fact!) Also post your measure 2 definition please.

Mark my post as solution if it was helpfull, thanks 🙂





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




Definately DIM and FACT as directed

Measure 2 =
VAR _select = SELECTEDVALUE(Dim[Phrase])
RETURN
if(SELECTEDVALUE('Fact'[Phrase])<>_select,1,0)

The first measure is the problem, my fault: This should work:

Measure =
VAR _selectphrase = SELECTEDVALUE(Dim[Phrase])
VAR _id= SUMMARIZE(FILTER(ALL('Fact'),'Fact'[Phrase]=_selectphrase),'Fact'[ID])
RETURN countx(FILTER('Fact','Fact'[ID] IN _id),'Fact'[Phrase])




Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




tamerj1
Super User
Super User

Hi @dsdesrosiers 

you need first to create a dim table (Phrases) that is connected to the main table (Phrases filters 'Table') that will be used as a slicer 

place 'Table'[Phrase] in a table visual along with the following measure 

Count =
CALCULATE ( COUNT ( 'Table'[ID] ), ALL ( Phrases ), VALUES ( 'Table'[ID] ) )

Unfortunately that did not do it either. I think I may need to explain differently. Imagine a pool of people with illnesses. Pick stroke. Return a list of everybody with a stoke history first. Then return a list of all related medical issues and a count of those issues. So high blood pressure would be a comorbidity. How many people with stroke also have high blood pressure? How many people with stroke have another related issue? Etc...

andhiii079845
Super User
Super User

I am sorry. I do not understand this. 🙂





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




andhiii079845
Super User
Super User

You mean the distinct count per item, right? 

(Avocado is 2 not 1, or? )

But phrase in the column of a matrix and use this measure:

MEASURE =
VAR _phrase = SELECTEDVALUE(Table[Phrase])
CALCULATE (
    DISTINCTCOUNT ( Table[ID] ),
    FILTER ( Table, Table[Phrase] = _phrase)
)

 





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




Thanks for the quick response...Avocado should be 1 ; and this isn't working unfortunately. What this is returning is the number of cases with Peanut, not the number of cases with the OTHER items that are in the same IDs as Peanut. 

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

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

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.

Top Solution Authors