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
El_Ha
Frequent Visitor

Need something similar to COUNTIF() across 2 unrelated tables in PowerBI

Hello,

 

Relatively new BI user here, I am struggling to make a small table in Power BI which will allow me to count the number of times each value in 1 table appears in another table.  My data appears as follows:

 

El_Ha_0-1596242616223.png

 

I have Referral table, which I created in the query editor. I created it using an mquery and converted it from a list into a table.

This just contains a list of all referral options that can appear on records (records can contain 1 or more referrals). 

 

The empty column here is where I would like to get a count for the number of times each of these options appears in the main table.

 

Secondly I have my main table with all the records extracted from the database(salesforce). 

 

Originally the Referral__c .1/2 columns were 1 column which had to be split as it was from a multi select picklist, and so values would appear in 1 line separated by a semicolon.

 

El_Ha_2-1596242987001.png

 

The table above has a basic filter which just removes any records that don't have referrals.

 

 

I am thinking this should be something relatively easy to do but I cannot seem to find a solution, I have tried to use Calculate and count functions and I have tried to create a relationship between the 2 tables so that I could use related function (this was not possible as the option is just greyed out).

I cannot seem to get some DAX to show how many times each of these options appears in the main table, or in 2 of the columns in the main table (Referral__c.1 and Referral__c.2)   A measure would also be fine for this I think?  I just need to be able to match the options in from my Referrals table to the number of times it is occuring in main table.

 

Any help would be greatly appreciated.

 

Thanks,

El

 

 

 

1 ACCEPTED SOLUTION
vivran22
Community Champion
Community Champion

Hello @El_Ha ,

 

From what I have understood, I have recreated the scenario below:

 

Sample tables:

Table 1.png

 

Table 2.png

 

Relationship

Relation.png

 

Formula:

 

Formula.png

 

For splitting the column, I would recommend that use the following option in Power Query:

Split.png

 

This way, you will have your all the results in one column.

 

Hope this helps.

 

Cheers!
Vivek

If it helps, please mark it as a solution. Kudos would be a cherry on the top 🙂
If it doesn't, then please share a sample data along with the expected results (preferably an excel file and not an image)

Blog: vivran.in/my-blog
Connect on LinkedIn
Follow on Twitter

View solution in original post

3 REPLIES 3
AllisonKennedy
Super User
Super User

@El_Ha
I also agree with @vivran22 that you should split the Referral column into rows. You can edit this in the Query Editor by clicking the settings cog next to the Split Columns by delimiter step and then follow the screenshot from @vivran22

I like that you have a referral table, but this is more useful if you have other information about each referral (such as Type, Location, start date, etc). As @vivran22 mentioned, you will need to make sure there is a 1 to many relationship between the Referral table and the data table.

To get the 'table' you want, you can use the Matrix visual and put:
Referral[Referral] in the Rows
Table[ID] in Values and set that to Count (or Count Distinct if you want how many unique ideas rather than how many total times it appears).


Please @mention me in your reply if you want a response.

Copying DAX from this post? Click here for a hack to quickly replace it with your own table names

Has this post solved your problem? Please Accept as Solution so that others can find it quickly and to let the community know your problem has been solved.
If you found this post helpful, please give Kudos C

I work as a Microsoft trainer and consultant, specialising in Power BI and Power Query.
www.excelwithallison.com

vivran22
Community Champion
Community Champion

Hello @El_Ha ,

 

From what I have understood, I have recreated the scenario below:

 

Sample tables:

Table 1.png

 

Table 2.png

 

Relationship

Relation.png

 

Formula:

 

Formula.png

 

For splitting the column, I would recommend that use the following option in Power Query:

Split.png

 

This way, you will have your all the results in one column.

 

Hope this helps.

 

Cheers!
Vivek

If it helps, please mark it as a solution. Kudos would be a cherry on the top 🙂
If it doesn't, then please share a sample data along with the expected results (preferably an excel file and not an image)

Blog: vivran.in/my-blog
Connect on LinkedIn
Follow on Twitter

Thats awesome! Thank you both so much 😊

 

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.