Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
4 years ago
Solved

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.

 

  • 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.

     

4 Replies

  • 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's avatar
      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.

      • amitchandak's avatar
        amitchandak
        Icon for Super User rankSuper User

        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.