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
Anonymous
Not applicable

Get row count (With condition?) from another table

Hi all,

 

First time posting here, I'm also new to Power BI and DAX.

I would like to get the row count from another table. There are 2 tables, Yield Table and Defect Table

 

Yield Table (Summarised):

DateModelProcessTotal Qty
20/2/2022ABCA10
21/2/2022ABCB14
21/2/2022DEFA15

 

Defect Table (Summarised):

DateModelProcessDefect Type
21/2/2022ABCAD1
21/2/2022ABCAD1
22/2/2022DEFAD2

 

I've made 2 Matrix visuals, Yield Matrix and Defect Matrix:

 

Yield Matrix (I would like to add the Defect D1, row count of defect type 'D1' from the defect table)

DateModelProcessTotal QtyDefect D1

February

  • 20
  • ABC
  • A
  • 10
  • 2
  • 21
  • ABC
  • A
  • 0
  • 0
  
  • B
  • 14
  • 0

 

Defect Matrix 

DateModelProcessDefect D1

February

  • 20
  • ABC
  • A
  • 2
  • 21
  • GHI
  • C
  • 2
  
  • D
  • 1

 

I was able to add a new measure to get the Defect D1 (Row count of defect type 'D1') using this formula:

Defect D1= CALCULATE(COUNTX(FILTER(Defects, Defects[Defect Type] = "D1"), Defects[Defect Type]))
 
I connected the 2 tables using Model (Many to Many), when I try to directly add the measure I added into the Yield Matrix, it will return the row count of defect type 'D1' from the whole table. For example:
 
DateModelProcessTotal QtyDefect D1

February

  • 20
  • ABC
  • A
  • 10
  • 2
  • 21
  • ABC
  • A
  • 0
  • 2
  
  • B
  • 14
  • 2

 

This is wrong because the row count should be based on the date, model and process. I have thought of making a new table to store the row count for every different date, model and process, but I'm not sure on how to do so, if this new table can be made, will it be updated automatically when the defect table is updated? 

 

Can anyone help me to solve this issue? Thanks in advance.

 

1 ACCEPTED SOLUTION

@Anonymous , ideal is you create Date, Model, Process table and join with both table and analyze the data with help of those. You need to be in star schema

https://www.sqlbi.com/articles/the-importance-of-star-schemas-in-power-bi/

 

For date you can create a date table using calendar

 

for model and Process , you can create table like

Model  = distinct(union(distinct(Table1[Model]),  distinct(Table2[Model]) ))

 


To get the best of the time intelligence function. Make sure you have a date calendar and it has been marked as the date in model view. Also, join it with the date column of your fact/s. Refer :radacad sqlbi My Video Series Appreciate your Kudos.

 

View solution in original post

4 REPLIES 4
VahidDM
Super User
Super User

HI @Anonymous 

 

Can you please add moe details about Defect Matrix. how did you create that and the logic behind that?

 

Also can you please add the desired output that you are looking for?

 


Appreciate your Kudos!!
LinkedIn: 
www.linkedin.com/in/vahid-dm/

 

 

Anonymous
Not applicable

Hi @VahidDM ,

 

The defect matrix is just to get the row count of Defect 'D1', for each day, model and process.

Defect Matrix Fields :

Rows :         

- Date

- Model

- Process

 

Value :

- Defect D1

 

DateModelProcessDefect Type
20/2/2022ABCAD1
20/2/2022ABCAD1
21/2/2022DEFAD1
21/2/2022DEFBD1
21/2/2022ABCAD1
21/2/2022ABCAD2

 

If I was to create a new table to store the data (Defect table) above, it should look like this :

 

DateModelProcessDefect D1
20/2/2022ABCA2
21/2/2022DEFA1
21/2/2022DEFB1
21/2/2022ABCA1

 

My desired output is to add the Defect D1 measure in the Yield Matrix, according to the Date, Model and Process of both table as shown on the Topic (Yield Matrix). Then, I would use this measure to deduct the Total field in the Yield Matrix.

 

I think that maybe I need to add more relationship between the 2 tables and the creation of new table is unnecessary, but I'm not sure how to do it.

@Anonymous , ideal is you create Date, Model, Process table and join with both table and analyze the data with help of those. You need to be in star schema

https://www.sqlbi.com/articles/the-importance-of-star-schemas-in-power-bi/

 

For date you can create a date table using calendar

 

for model and Process , you can create table like

Model  = distinct(union(distinct(Table1[Model]),  distinct(Table2[Model]) ))

 


To get the best of the time intelligence function. Make sure you have a date calendar and it has been marked as the date in model view. Also, join it with the date column of your fact/s. Refer :radacad sqlbi My Video Series Appreciate your Kudos.

 

Anonymous
Not applicable

Hi @amitchandak,

 

I'm not sure if I did it correctly, I just added 3 Dim tables each with 1 column and connected them to both of the table with one to many. Then, I updated my matrix fields with the new table columns, I think it is working.

 

Thanks a lot for your help! Much appriciated!! Please let me know if there were any mistakes I made.

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.