Forum Discussion

Leon12Smith's avatar
Leon12Smith
Frequent Visitor
3 years ago
Solved

Count Rows of Joined Tables with multiple conditions

Hi

I am able to create this Table Visualisation in Power BI by dragging in columns from different tables and applying the appropriate filters in the Filters Pane on this specific Visual. The filters are obvious as per the table values but the only strange condition is Written Amount > 0. This results in 15x unique Product Numbers as per the table. I need a measure that can calculate the row count of the table below that equals 15 unique Product Numbers based on the filter conditions applied. 


The columns listed in the Table Visualisation are in the following tables in the database and there are active relationships (direct and indirect relationships - through other tables not listed) between these tables in the model:

1. Database Table A contains the following columns:
- Product Number
- Product Line
- Product Type
- Product Sub-Type
- Status
- Origin

2. Database Table B contains the following column:

- Period

3. Database Table C contains the following column:

- Direct or Indirect

4. Database Table D contains the following column:

- Written Movement

Please assist. I can't share the data.



  • CALCULATE(COUNTROWS("correct_table"), Filter1, Filter2, etc) resolved this.

    Was using the incorrect table thanks. 

3 Replies

  • some_bih's avatar
    some_bih
    Icon for Community Champion rankCommunity Champion

    Hi Leon12Smith usually measure for count number of rows for some of table is 

    Count rows=COUNTROWS ( table )

    Adjust your table name

    If you filter something and want to calculate "the rest" number of rows meaning non filtered rows you should use

    Count rows rest =
    VAR __rows_all=CALCULATE (

                COUNTROWS ( table ),
                 ALL()             

    )

    VAR __rows_allselected=CALCULATE (

                COUNTROWS ( table ),
                 ALLSELECTED()             

    )

    VAR __Result=__rows_all-__rows_allselected

    RETURN __Result

     

    Did I answer correctly?

    Kudos appreciate / accept solution



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

      some_bih, there is an additional condition "Written Amount > 0" mentioned.
      Maybe something like this:

      Rows = 
          CALCULATE(
              COUNTROWS(yout_table),
              Written Amount > 0
              )


      Leon12Smith Just an extended idea to suggested solution from some_bih 

       

      Regards

  • Leon12Smith's avatar
    Leon12Smith
    Frequent Visitor

    CALCULATE(COUNTROWS("correct_table"), Filter1, Filter2, etc) resolved this.

    Was using the incorrect table thanks.