Forum Discussion

Topside's avatar
Topside
Frequent Visitor
4 years ago
Solved

Measure to divide counted rows based on corresponding column value from different table

Hello everyone, hope you are well.

I am trying to figure out how to DIVIDE some counted rows based on a related group from another table.  I need the count of rows from Table 2 based on the corresponding Product Type and Standard from Table 1. 
(for example, since there are 3 "AA" rows counted from Table 2, divide the count(3) by the corresponding Standard from table 1(3).

I've only been able to achieve division based on a single condition thus far and I've been stuck on this for awhile.  I do have these tables related as well.
Can someone please help?  I have table examples listed below.
Thank you!

Table 1:

Product TypeStandard

AA

3
BB4
CC8


Table 2:

IDDateProduct
X4504/22/2022BB
X4604/26/2022AA
X4704/28/2022AA
X483/17/2022CC
X493/29/2022AA





  • Hi Topside ,

    If you need to to get the count of rows for each produc, you can do something like this

     

    Row count for each product =
    CALCULATE ( COUNTROWS ( Table2 ), ALLEXCEPT ( Table2, Table2[Product] ) )

     

    For AA, this will show 3 for each ID. You can then use the measure above as the second argument in DIVIDE.

8 Replies

  • Hi Topside 

     

    Try this measure:

    Count Divide = 
    Var _PT = MAX('Table 1'[Product Type])
    Var _ST = MAX('Table 1'[Standard])
    Var _T2R = CALCULATE(COUNTROWS('Table 2'),FILTER('Table 2' ,'Table 2'[Product]=_PT))
    return
    _T2R/_ST

     

    Output:

     

     

     

     

    If this post helps, please consider accepting it as the solution to help the other members find it more quickly.
    Appreciate your Kudos!!
    LinkedIn: 
    www.linkedin.com/in/vahid-dm/

     

     

    • Topside's avatar
      Topside
      Frequent Visitor

      Hello Vahid, I attempted this but it didn't achieve what I was looking for.  

      Basically I want a measure I can plug into my current table visualization that shows the counted rows of each of the categories(that are filtered out as the visualization has prexisting filters already).  Then, I want to divide the COUNT by the corresponding value from Table 1 to the product type of Table 2. Something that includes something like this perhaps?:

      CALCULATE(
      COUNTROWS(Table2),
      FILTER(Table2, Table2[Product] = "BB") *** need the count for each of the type of products and still divide on the matching, though
    • Topside's avatar
      Topside
      Frequent Visitor

      Hello Dan, thank you for taking time to answer.  This didn't get the solution I was looking for.
      Basically I want a measure I can plug into my current table visualization that shows the counted rows of each of the categories(that are filtered out as the visualization has prexisting filters already).  Then, I want to divide the COUNT by the corresponding value from Table 1 to the product type of Table 2. Something that includes something like this perhaps?:

      CALCULATE(
      COUNTROWS(Table2),
      FILTER(Table2, Table2[Product] = "BB") *** need the count for each of the type of products and still divide on the matching, though


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

        Hi Topside ,

        If you need to to get the count of rows for each produc, you can do something like this

         

        Row count for each product =
        CALCULATE ( COUNTROWS ( Table2 ), ALLEXCEPT ( Table2, Table2[Product] ) )

         

        For AA, this will show 3 for each ID. You can then use the measure above as the second argument in DIVIDE.

  • Hi Topside ,

    Is your problem solved?? If so, Would you mind accept the helpful replies as solutions? Then we are able to close the thread. More people who have the same requirement will find the solution quickly and benefit here. Thank you.

    Best Regards,
    Community Support Team _ kalyj