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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
pawelk3
Helper I
Helper I

Count rows from related table (M2M)

Hi,

I have two tables: 'Lead' and "Contact' with relation many to many using keys Lead[ParentContactId] and Contact[ContactId]. I want to create a measure in leads table to count number of matching contact records for each lead based on few criteria:

 

  1. Contact[ContractDate] > Lead[CreatedOn] AND Contact[ContractDate] <= Lead[CreatedOn] + 90
  2. if there is no matching contact record or there is no contract for particular contact record (Contact[ContractId] = BLANK()) then show 0

Then I want to split this count equally for each matching lead, so if there are two contact records meeting the criteria for particular lead and two leads with the same 'ParentContactId' then show 1 for each lead.

Each 'Contact' record represents one purchase so that is why contact ids are duplicated. I can group them to get unique records and many to one relation between the tables. I tried it but I have problem with referencing columns that have been grouped as table structured column.

 

I got to that point and got stuck:

 

 

Conversions = 
CALCULATE(
    COUNTROWS(Contact),
    FILTER(
        ALL(Contact),
        COUNTROWS(
            FILTER(
                RELATEDTABLE(Contact),
                Contact[ContractDate] >= Lead[CreatedOn] &&
                Contact[ContractDate] <= Lead[CreatedOn] + 90
            )
        ) > 0
    )
)

 

 

I am getting an error: "A single value for column 'CreatedOn' in table 'Lead' cannot be determined. This can happen when a measure formula refers to a column that contains many values without specifying an aggregation such as min, max, count, or sum to get a single result." probably because of many to many relation.

 

I would be very grateful if someone would like to guide me on how to solve this

1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi @pawelk3 ,

It seems that what you are trying to create is a measure, please update the formula of measure[Conversions] as below. Later check if it can return your expected result...

Conversions =
VAR _seldate =
    SELECTEDVALUE ( Lead[CreatedOn] )
RETURN
    CALCULATE (
        COUNT ( Contact[ContactId] ),
        FILTER (
            Contact,
            Contact[ContractDate] >= _seldate
                && Contact[ContractDate] <= _seldate + 90
        )
    )

In addition, you can review the following blog to know the common DAX errors...

DAX error messages in Power BI

 

If the above one can't help you, please provide some raw data in your table (exclude sensitive data) with Text format, your treemap Fields settings and your expected result with backend logic and special examples? It would be helpful to find out the solution. You can refer the following links to share the required info:

How to provide sample data in the Power BI Forum

How to Get Your Question Answered Quickly

And It is better if you can share a simplified pbix file. You can refer the following link to upload the file to the community. Thank you.

How to upload PBI in Community

Best Regards

View solution in original post

1 REPLY 1
Anonymous
Not applicable

Hi @pawelk3 ,

It seems that what you are trying to create is a measure, please update the formula of measure[Conversions] as below. Later check if it can return your expected result...

Conversions =
VAR _seldate =
    SELECTEDVALUE ( Lead[CreatedOn] )
RETURN
    CALCULATE (
        COUNT ( Contact[ContactId] ),
        FILTER (
            Contact,
            Contact[ContractDate] >= _seldate
                && Contact[ContractDate] <= _seldate + 90
        )
    )

In addition, you can review the following blog to know the common DAX errors...

DAX error messages in Power BI

 

If the above one can't help you, please provide some raw data in your table (exclude sensitive data) with Text format, your treemap Fields settings and your expected result with backend logic and special examples? It would be helpful to find out the solution. You can refer the following links to share the required info:

How to provide sample data in the Power BI Forum

How to Get Your Question Answered Quickly

And It is better if you can share a simplified pbix file. You can refer the following link to upload the file to the community. Thank you.

How to upload PBI in Community

Best Regards

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

November Power BI Update Carousel

Power BI Monthly Update - November 2025

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

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.