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

Get Fabric Certified for FREE during Fabric Data Days. Don't miss your chance! Learn more

Reply
N_R_000
Helper I
Helper I

Capturing Selected occurrences with a many to many relationship

I'm going to need a few images to help explain this one:

 

Here's my dataset (I can't change the structure) of people who have trialed various products, then either purchased them (or not). 

N_R_000_0-1599232010848.png

 

Here are the relationships (Trials_Split is just the [Trials] table but the ProductsTrialed column has been split into rows based on the comma delimeter): 

N_R_000_1-1599232057406.png

 

I have a number of reporting requirements that I'm really struggling to achieve, and could do with the communitys help on: 

 

The main thing is linking a trial of a product to the purchae of that product but has to be AFTER the trial happened and within 30 days. 

 

1) Did the customer purchase the same product that they trialed within 30 days of the trial?

2) Did they purchase ANY product within 30 days of a trial? 

3) Which trial products were purchased most? A count for each. 

 

I was hoping to do this with a few flags as calculated columns, but due to the many-many relationship I can't find a way.

 

Really appreciate any help you can give.  

1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi @N_R_000 

To have a test I update my Trial Table, Sales Table(add customer 6 trial id 23 and bought Bike 22) and Product Table.

Trial Table:

1.png

Sales Table:

2.png

Product Table:

3.png

Relationships:

4.png

I think you can add a Product Name Column in Trial_Split Table. Update the Flag column and other steps are the same.

 

 

LatestTrailDate = MAXX(FILTER(Trials_Split,Trials_Split[CustomerID]=EARLIER(Trials_Split[CustomerID])),Trials_Split[Date])
Product Name = 
VAR ProductID = Trials_Split[ProductID]
RETURN 
CALCULATE(SELECTEDVALUE('Product'[ProductName]),ALL(Trials_Split),'Product'[ProductID]=ProductID)
Flag = 
VAR _1 =
    CALCULATE (
        MAX (Trials_Split[LatestTrailDate] ),
        FILTER (
            Trials_Split,
            Trials_Split[CustomerID] = EARLIER ( Sales[CustomerID] )
                && Trials_Split[Product Name] = EARLIER ( Sales[ProductName] )
        )
    )
VAR _DayDiff =
    DATEDIFF ( _1, Sales[SaleDate], MONTH )
RETURN
    IF (
        _1 = BLANK (),
        "Not a Trail Product",
        IF (
            _DayDiff < 0,
            "Bought Before Trail",
            IF (
                _DayDiff <= 1,
                "Bought After Trail",
                "Bought But More than 1 month after Trail"
            )
        )
    )

 

 

Result:

5.png

You can download the pbix file from this link: Capturing Selected occurrences with a many to many relationship

 

Best Regards,

Rico Zhou

 

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly. 

View solution in original post

7 REPLIES 7
Anonymous
Not applicable

Hi @N_R_000 

Could you tell me if your problem has been solved? If it is, kindly Accept it as the solution. More people will benefit from it. Or you are still confused about it, please provide me with more details about your table and your problem or share me with your pbix file from your Onedrive for Business.

 

Best Regards,

Rico Zhou

Anonymous
Not applicable

Hi @N_R_000 

I build three tables like yours and add calculated columns in these tables.

Trail Table:

1.png

Transform this table to Trail_Split and add a LatestTrailDate column in it.

LatestTrailDate = MAXX(FILTER(Trials_Split,Trials_Split[CustomerID]=EARLIER(Trials_Split[CustomerID])),Trials_Split[Date])

5.png

Sales Table add ProductID

ProductID = RELATED('Product'[ProductID])

6.png

Product Table:

3.png

Your Sales Table can't get product Id from Product Table by your relationship. You can build a relationship as below.

7.png

Then add a new calculated column in Sales table.

Flag = 
VAR _1 =
    CALCULATE (
        MAX (Trials_Split[LatestTrailDate] ),
        FILTER (
            Trials_Split,
            Trials_Split[CustomerID] = EARLIER ( Sales[CustomerID] )
                && Trials_Split[ProductID] = EARLIER ( Sales[ProductID] )
        )
    )
VAR _DayDiff =
    DATEDIFF ( _1, Sales[SaleDate], MONTH )
RETURN
    IF (
        _1 = BLANK (),
        "Not a Trail Product",
        IF (
            _DayDiff < 0,
            "Bought Before Trail",
            IF (
                _DayDiff <= 1,
                "Bought After Trail",
                "Bought But More than 1 month after Trail"
            )
        )
    )

Result:

8.png

For more info to relationships in power bi: Create and manage relationships in Power BI Desktop

You can download the pbix file from this link: Capturing Selected occurrences with a many to many relationship

 

Best Regards,

Rico Zhou

 

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly. 

Hi @Anonymous 


Thank you, your help is really appreciated and has gotten me 90% of the way there. 

 

However, there is one issue I have: The data in the Product table actually creates a many to many relationship with the Sales table. 

This is because Trials are conducted under a 'Trial Product Name', and many of those trial products can link to just 1 sellable 'Product Name', like this: 

 

N_R_000_2-1599576340998.png

So that leaves me with a join like this - many to many 😞 

N_R_000_0-1599576090737.png

 

Is there a way I can achieve what you've already described, but with that relationship? 

 

I've tried changing the second clause in the filter to: 

&& Trials_Split[ProductID] = EARLIER ( Sales[ProductName] )

but every row get the 'Not a trial Product' result. 

Anonymous
Not applicable

Hi @N_R_000 

I change the Product table like yours, and build relationships between these tables.

1.png

Relationships:

2.png

I update the calculated column to add Product ID column into Sales Table.

ProductID = CALCULATE(MAX('Product'[ProductID]),FILTER('Product','Product'[ProductName]=EARLIER(Sales[ProductName])))

 And other steps are the same as above.

Result:

3.png

If this reply still couldn't help you solve your problem, please show me more details about your relationships.

And I just see Trial ProductName column in Product Table, other tables don't contain it. Will you use it in the future?

Or you can provide me with your pbix file by your OneDrive for Business.

You can download the pbix file from this link: Capturing Selected occurrences with a many to many relationship

 

Best Regards,

Rico Zhou

 

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly. 

Hi @Anonymous  Thank again, deginitely closer! 

 

I got the data slightly wrong (sorry), which I need to explain more about: 

 

I've highlighted CustomerID 1 below; 

They trialed ProductIDs 22, 56 and 11. 

ProductID 22 links to 'ProductName' 'Bike22' but as you can see, 'Bike22' is linked to multiple trial bikes (ID 22 and 23). 

N_R_000_0-1599657732172.png

 

If I add your 'ProductID' Calculated Column to the Sales table, I get this result for CustomerID 1

N_R_000_1-1599657875581.png

It's not finding the link to the trial product because the MAX function returns 23; but I'd have the same problem if I switched it to MIN and the customer trialed ProductID 22.  

 

I have the same relationship view as you: 

N_R_000_2-1599657959765.png

 

And TrialSplit looks like this: 

N_R_000_3-1599657978577.png

 

In basic terms: "If the customer bought a bike which has a matching 'ProductName' to one he trialed, then it's a Match"

 

I can't share a OneDrive folder as it's a work problem, do you have an email address I could forward it to? 

 

Anonymous
Not applicable

Hi @N_R_000 

To have a test I update my Trial Table, Sales Table(add customer 6 trial id 23 and bought Bike 22) and Product Table.

Trial Table:

1.png

Sales Table:

2.png

Product Table:

3.png

Relationships:

4.png

I think you can add a Product Name Column in Trial_Split Table. Update the Flag column and other steps are the same.

 

 

LatestTrailDate = MAXX(FILTER(Trials_Split,Trials_Split[CustomerID]=EARLIER(Trials_Split[CustomerID])),Trials_Split[Date])
Product Name = 
VAR ProductID = Trials_Split[ProductID]
RETURN 
CALCULATE(SELECTEDVALUE('Product'[ProductName]),ALL(Trials_Split),'Product'[ProductID]=ProductID)
Flag = 
VAR _1 =
    CALCULATE (
        MAX (Trials_Split[LatestTrailDate] ),
        FILTER (
            Trials_Split,
            Trials_Split[CustomerID] = EARLIER ( Sales[CustomerID] )
                && Trials_Split[Product Name] = EARLIER ( Sales[ProductName] )
        )
    )
VAR _DayDiff =
    DATEDIFF ( _1, Sales[SaleDate], MONTH )
RETURN
    IF (
        _1 = BLANK (),
        "Not a Trail Product",
        IF (
            _DayDiff < 0,
            "Bought Before Trail",
            IF (
                _DayDiff <= 1,
                "Bought After Trail",
                "Bought But More than 1 month after Trail"
            )
        )
    )

 

 

Result:

5.png

You can download the pbix file from this link: Capturing Selected occurrences with a many to many relationship

 

Best Regards,

Rico Zhou

 

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly. 

amitchandak
Super User
Super User

@N_R_000 , You should have a common date and customer table remove join  M-M joins

https://www.seerinteractive.com/blog/join-many-many-power-bi/

https://www.sqlbi.com/articles/the-importance-of-star-schemas-in-power-bi/

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

Helpful resources

Announcements
Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

October Power BI Update Carousel

Power BI Monthly Update - October 2025

Check out the October 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.

Top Solution Authors