cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
keivan
Helper I
Helper I

Calculate the number of Distinct subject - joining data from 3 tables

Hi all,

I would like to calculate the number of distinct Subject.
My dataset is compose in this way:

 

Calendar Table (Date, Year, Month, etc.)
Subject Table (Subject_id, Name, Surname, etc.)
Connections Table (Subject_id, Connection_id, etc.)
Fetches Table (Fetch_id, Connection_id, Flag_error, etc.)


On SQL I would do

SELECT DISTINCT subject_id
FROM subjects s

inner join connections c on c.subject_id = s.subject_id
inner join fetches f on f.connection_id = c.connection_id

 

where f.flag_error = 0

 

Infact I want to calculate distinct subject (where subject_id are store on the subjects table) and I need to join with the fetches table, however there is not a direct key from fetches table and subject table, so I need the connection table as a bridge.

Furthermore I want to calculate only the subject where the donwload of the data (fetch) is not an error (flag_error = 0)

Sorry to bother you, but I don't know how to join multiple table as a variable in BI 
Thanks,

1 ACCEPTED SOLUTION
keivan
Helper I
Helper I

PSU= Calculate(DISTINCTCOUNT( subjects[subject_business_id]), FILTER ('fetches', fetches[flag_error] = 0))

I didn't realize that having a relationship I didn't need to join and I was already able to perform cross filter

View solution in original post

2 REPLIES 2
keivan
Helper I
Helper I

PSU= Calculate(DISTINCTCOUNT( subjects[subject_business_id]), FILTER ('fetches', fetches[flag_error] = 0))

I didn't realize that having a relationship I didn't need to join and I was already able to perform cross filter

djurecicK2
Memorable Member
Memorable Member

Hi @keivan ,

 You can join tables in Power BI, but many times relating tables is a better option.

Here is some additional information:

https://learn.microsoft.com/en-us/power-bi/transform-model/desktop-create-and-manage-relationships

 

https://radacad.com/combine-tables-or-create-relationships-the-power-bi-modeling-best-practice

 


If this post helps, then please consider accepting it as the solution to help other members find it more quickly.

Helpful resources

Announcements
Carousel_PBI_Wave1

2023 Release Wave 1 Plans

Power BI release plans for 2023 release wave 1 describes all new features releasing from April 2023 through September 2023.

Power BI Summit Carousel 2

Global Power BI Training

Make sure you register today for the Power BI Summit 2023. Don't miss all of the great sessions and speakers!

BizApps LATAM 2023

Business Application LATAM Summit 2023

Join the biggest FREE Business Applications Event in LATAM this February.

Power Platform Bootcamp

Global Power Platform Bootcamp

In this bootcamp we will deep-dive into Microsoft’s Power Platform stack with hands-on sessions and labs, delivered to you by experts and community leaders.

Top Solution Authors
Top Kudoed Authors