Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.

Reply
Bia
New Member

Count values from Many to One relationship with a condition

Hello!

I am new to Power BI and I have been struggling with letting go from the Excel mentality... I have a Table 1 that looks something like this:

SHIPMENT NUMBERPRODUCTCOUNTRY CODE
1Orange1234
6Orange1567
1Apple1234
7Grapes1234
8Apple8907

 

And it is related to another table (Table 2) by the COUNTRY CODE, but in this table there is only a row for each code, for example:

COUNTRY CODE
1234
8907
1567
9876

 

So they have a Many to One relationship

 

I need to create a column in Table 2 (the ONE side of the relationship) that has the COUNT OF DISTINCT Shipments for each of the country codes, but WITH THE CONDITION of only counting the shipments that have Oranges:

COUNTRY CODEORANGE SHIPMENTS
12345
15677

 

I can't only filter the visuals because I need the total value for each country so I can then validate the number of shipments by an If statement on another column of "If it is higher than 10, then 0.2, if not 0"... and then use the value for more calculations.

I have tried the calculate function in the Table 2 column, but it did not seem to work, it returned no value at all:

 

Orange Shipments= CALCULATE(
    DISTINCTCOUNT('Table 1'[Shipment Number]),
    'Table 1'[Product]= "Orange")

 

 

Please, how can I summarize the count of shipments with oranges by country? This has been making me crazy.

 

Thank you! 

2 ACCEPTED SOLUTIONS
Jihwan_Kim
Super User
Super User

Hi,

Please try the below. It is for creating a new column.

 

Orange shipments count CC =
COUNTROWS (
    SUMMARIZE (
        FILTER ( RELATEDTABLE ( 'Table1' ), 'Table1'[PRODUCT] = "Orange" ),
        'Table1'[SHIPMENT NUMBER]
    )
)

If this post helps, then please consider accepting it as the solution to help other members find it faster, and give a big thumbs up.


Click here to visit my LinkedIn page

Click here to schedule a short Teams meeting to discuss your question.

View solution in original post

Anonymous
Not applicable

Hi @Bia ,

 

Please check this formula:

Column =
CALCULATE (
    DISTINCTCOUNT ( 'Table 1'[SHIPMENT NUMBER] ),
    FILTER (
        'Table 1',
        'Table 1'[COUNTRY CODE] = 'Table 2'[COUNTRY CODE]
            && 'Table 1'[PRODUCT] = "Orange"
    )
)

vjaywmsft_0-1654851198273.png

 

Best Regards,

Jay

View solution in original post

2 REPLIES 2
Anonymous
Not applicable

Hi @Bia ,

 

Please check this formula:

Column =
CALCULATE (
    DISTINCTCOUNT ( 'Table 1'[SHIPMENT NUMBER] ),
    FILTER (
        'Table 1',
        'Table 1'[COUNTRY CODE] = 'Table 2'[COUNTRY CODE]
            && 'Table 1'[PRODUCT] = "Orange"
    )
)

vjaywmsft_0-1654851198273.png

 

Best Regards,

Jay

Jihwan_Kim
Super User
Super User

Hi,

Please try the below. It is for creating a new column.

 

Orange shipments count CC =
COUNTROWS (
    SUMMARIZE (
        FILTER ( RELATEDTABLE ( 'Table1' ), 'Table1'[PRODUCT] = "Orange" ),
        'Table1'[SHIPMENT NUMBER]
    )
)

If this post helps, then please consider accepting it as the solution to help other members find it faster, and give a big thumbs up.


Click here to visit my LinkedIn page

Click here to schedule a short Teams meeting to discuss your question.

Helpful resources

Announcements
July 2025 community update carousel

Fabric Community Update - July 2025

Find out what's new and trending in the Fabric community.

July PBI25 Carousel

Power BI Monthly Update - July 2025

Check out the July 2025 Power BI update to learn about new features.

Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.