<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Find cross brand buyers in DAX Commands and Tips</title>
    <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Find-cross-brand-buyers/m-p/4358692#M173045</link>
    <description>&lt;P&gt;Thanks. I already tried S&lt;SPAN&gt;ELECTEDVALUE(ecom_brands[Name]) but that didn't work, so i switched to CALCULATE(x).&lt;BR /&gt;&lt;BR /&gt;Do I understand correctly that you are advising to create a 'separate' table for CustomersOfSelectedBrand? In that piece of code, you use SelectedBrandID. So, I first need to declare that as a VAR?&amp;nbsp;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;</description>
    <pubDate>Fri, 10 Jan 2025 11:48:37 GMT</pubDate>
    <dc:creator>TutanRamon</dc:creator>
    <dc:date>2025-01-10T11:48:37Z</dc:date>
    <item>
      <title>Find cross brand buyers</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Find-cross-brand-buyers/m-p/4358647#M173042</link>
      <description>&lt;P&gt;I run a webshop and have all the sales data imported in PowerBI. So far, so good, but I want to create a next level visual. I am planning to use Microsoft's Force Directed Graph. Therefore, I need a virtual table&lt;BR /&gt;&lt;BR /&gt;SourceBrand | TargetBrand | Number of Customers&lt;BR /&gt;&lt;BR /&gt;So, I select a brand from the brand list, let's say Sony. Then I want to find the customer count for each other brand they buy as well. This is an example output I desire:&lt;BR /&gt;Sony | Philips | 10&lt;BR /&gt;Sony | Bosch | 54&lt;BR /&gt;Sony | KG | 22&lt;BR /&gt;Sony | Plass | 4&lt;BR /&gt;etc.&lt;BR /&gt;&lt;BR /&gt;I am struggling with the DAX-code for this. Somehow, the slicer value isn't being used in the calculation.&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;BrandCrossPurchasesMeasure =
VAR SelectedBrand = CALCULATE(SELECTEDVALUE(ecom_brands[Name], "Sony"))
VAR SelectedBrandID =
	CALCULATE(
		MIN(ecom_brands[brandId]),
		ecom_brands[Name] = SelectedBrand
)
VAR CustomersOfSelectedBrand =
	CALCULATETABLE(
		DISTINCT(ecom_invoices[customerId]),
		FILTER(
			ecom_sales,
			RELATED(ecom_products[brandId]) = SelectedBrandID
		)
	)

RETURN
	SUMMARIZE(
		VALUES(ecom_brands[Name]),
		ecom_brands[Name], -- TARGET
		"SOURCE", SelectedBrand,
		"CUSTOMERCOUNT",
		COUNTROWS(
			INTERSECT(
				CustomersOfSelectedBrand,
				CALCULATETABLE(
					DISTINCT(ecom_invoices[customerId]),
					FILTER(
						ecom_sales,
						RELATED(ecom_products[brandId]) =
							CALCULATE(
								MIN(ecom_brands[brandId]),
								ecom_brands[Name] = ecom_brands[Name]
							)
					)
				)
			)
		)
	)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Data model:&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P class=""&gt;ecom_customers (customerId, Name etc.)&lt;/P&gt;&lt;P class=""&gt;ecom_products (productId, brandId, price, name etc.)&lt;/P&gt;&lt;P class=""&gt;ecom_sales (salesrow_id, invoiceId, productId, amount, totalprice etc.)&amp;nbsp; (basically these are the invoice rows)&lt;/P&gt;&lt;P class=""&gt;ecom_brands (brandId, Name etc.)&lt;/P&gt;&lt;P class=""&gt;ecom_invoices (InvoiceId, customerId, totalAmount, tax etc.)&lt;/P&gt;&lt;P class=""&gt;&amp;nbsp;&lt;/P&gt;&lt;P class=""&gt;Relations&lt;/P&gt;&lt;P class=""&gt;ecom_customers(customerId) 1: n with ecom_invoices(customerId)&lt;/P&gt;&lt;P class=""&gt;ecom_products (productId) 1:n with ecom_sales(productId)&lt;/P&gt;&lt;P class=""&gt;ecom_products (productId) n:1 with ecom_brands(brandId)&lt;/P&gt;&lt;P class=""&gt;ecom_invoices(invoiceId) 1:n with ob_sales(invoiceId)&lt;BR /&gt;&lt;BR /&gt;Can somebody explain why the selectedBrand isn't used in the calculation. Might have something to do with context, but how to fix this? Because the fallback value "Sony" is working in this case, but it needs to be dynamic.&lt;/P&gt;</description>
      <pubDate>Fri, 10 Jan 2025 10:55:22 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Find-cross-brand-buyers/m-p/4358647#M173042</guid>
      <dc:creator>TutanRamon</dc:creator>
      <dc:date>2025-01-10T10:55:22Z</dc:date>
    </item>
    <item>
      <title>Re: Find cross brand buyers</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Find-cross-brand-buyers/m-p/4358679#M173043</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="javascript:void(0)" data-lia-user-mentions="" data-lia-user-uid="545514" data-lia-user-login="TutanRamon" class="lia-mention lia-mention-user"&gt;TutanRamon&lt;/a&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The issue is that the slicer value isn't propagating due to context problems. To fix this:&lt;/P&gt;&lt;OL&gt;&lt;LI&gt;&lt;P&gt;&lt;STRONG&gt;Dynamic Brand Selection&lt;/STRONG&gt;: Use SELECTEDVALUE(ecom_brands[Name]) to dynamically get the brand selected in the slicer.&lt;/P&gt;&lt;/LI&gt;&lt;LI&gt;&lt;P&gt;&lt;STRONG&gt;Filter Customers&lt;/STRONG&gt;: Create a table of customers who bought the selected brand using:&lt;/P&gt;&lt;/LI&gt;&lt;/OL&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;CustomersOfSelectedBrand =
CALCULATETABLE(
    DISTINCT(ecom_invoices[customerId]),
    FILTER(
        ecom_sales,
        RELATED(ecom_products[brandId]) = SelectedBrandID
    )
)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;&lt;STRONG&gt;Find Overlap&lt;/STRONG&gt;: Use INTERSECT to count customers who bought both the selected brand and other brands.&lt;/LI&gt;&lt;LI&gt;&lt;STRONG&gt;Summarize Results&lt;/STRONG&gt;: Build a virtual table excluding the selected brand:&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;RETURN
SUMMARIZE(
    FILTER(ecom_brands, ecom_brands[Name] &amp;lt;&amp;gt; SelectedBrand),
    ecom_brands[Name],
    "SOURCE", SelectedBrand,
    "CUSTOMERCOUNT",
    COUNTROWS(
        INTERSECT(
            CustomersOfSelectedBrand,
            CALCULATETABLE(
                DISTINCT(ecom_invoices[customerId]),
                FILTER(
                    ecom_sales,
                    RELATED(ecom_products[brandId]) = ecom_brands[brandId]
                )
            )
        )
    )
)
​&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;&lt;P&gt;This will dynamically generate a table showing customer counts for cross-brand purchases.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Did I answer your question? Mark my post as a solution, this will help others!&lt;/STRONG&gt;&lt;BR /&gt;If my response(s) assisted you in any way, don't forget to drop me a "&lt;STRONG&gt;Kudos&lt;/STRONG&gt;" &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;&lt;P&gt;Kind Regards,&lt;BR /&gt;Poojara&lt;BR /&gt;Data Analyst | MSBI Developer | Power BI Consultant&lt;BR /&gt;&lt;STRONG&gt;Consider Subscribing my YouTube for Beginners/Advance Concepts:&lt;A href="http:// https://youtube.com/@biconcepts?si=04iw9SYI2HN80HKS" target="_self"&gt; https://youtube.com/@biconcepts?si=04iw9SYI2HN80HKS&lt;/A&gt;&amp;nbsp;&lt;/STRONG&gt;&lt;/P&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;&amp;nbsp;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/LI&gt;&lt;/UL&gt;</description>
      <pubDate>Fri, 10 Jan 2025 11:25:10 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Find-cross-brand-buyers/m-p/4358679#M173043</guid>
      <dc:creator>Poojara_D12</dc:creator>
      <dc:date>2025-01-10T11:25:10Z</dc:date>
    </item>
    <item>
      <title>Re: Find cross brand buyers</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Find-cross-brand-buyers/m-p/4358692#M173045</link>
      <description>&lt;P&gt;Thanks. I already tried S&lt;SPAN&gt;ELECTEDVALUE(ecom_brands[Name]) but that didn't work, so i switched to CALCULATE(x).&lt;BR /&gt;&lt;BR /&gt;Do I understand correctly that you are advising to create a 'separate' table for CustomersOfSelectedBrand? In that piece of code, you use SelectedBrandID. So, I first need to declare that as a VAR?&amp;nbsp;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 10 Jan 2025 11:48:37 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Find-cross-brand-buyers/m-p/4358692#M173045</guid>
      <dc:creator>TutanRamon</dc:creator>
      <dc:date>2025-01-10T11:48:37Z</dc:date>
    </item>
    <item>
      <title>Re: Find cross brand buyers</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Find-cross-brand-buyers/m-p/4358742#M173050</link>
      <description>&lt;P&gt;Ok, I now have this:&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;CustomersOfSelectedBrand = 
VAR SelectedBrand = SELECTEDVALUE(ecom_brands[Name])

VAR SelectedBrandID = 
	CALCULATE(
		MIN(ecom_brands[BrandId]),
		ecom_brands[Name] = SelectedBrand
)
RETURN
CALCULATETABLE(
    DISTINCT(ecom_invoices[CustomerId]),
    FILTER(
        ecom_sales,
        RELATED(ecom_products[BrandID]) = SelectedBrand
    )
)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;But, this keeps giving me the same list, regardless the brand i am choosing in the slicer.&lt;/P&gt;</description>
      <pubDate>Fri, 10 Jan 2025 12:32:31 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Find-cross-brand-buyers/m-p/4358742#M173050</guid>
      <dc:creator>TutanRamon</dc:creator>
      <dc:date>2025-01-10T12:32:31Z</dc:date>
    </item>
    <item>
      <title>Re: Find cross brand buyers</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Find-cross-brand-buyers/m-p/4360717#M173102</link>
      <description>&lt;P&gt;Thank you for the reply from&amp;nbsp;Poojara_D12&amp;nbsp;!&lt;/P&gt;
&lt;P&gt;Hi&amp;nbsp;&lt;a href="javascript:void(0)" data-lia-user-mentions="" data-lia-user-uid="545514" data-lia-user-login="TutanRamon" class="lia-mention lia-mention-user"&gt;TutanRamon&lt;/a&gt;&amp;nbsp;,&lt;/P&gt;
&lt;P&gt;Try to change RELATED(ecom_products[BrandID]) in the FILTER function to&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;RELATED(ecom_products[BrandID]) = SelectedBrandID.&lt;/LI-CODE&gt;
&lt;P&gt;If it still doesn't return the results you need, try simplifying the code and troubleshooting the problem step by step. For example, you could start by returning just the value of SelectedBrandID to see if it's correct, and then gradually add the rest. Or could you please provide some&amp;nbsp;&lt;STRONG&gt;raw data&lt;/STRONG&gt;&amp;nbsp;in your tables&amp;nbsp;(&lt;STRONG&gt;&lt;EM&gt;exclude&amp;nbsp;sensitive&amp;nbsp;data&lt;/EM&gt;&lt;/STRONG&gt;) with&amp;nbsp;&lt;STRONG&gt;Text&lt;/STRONG&gt;&amp;nbsp;format and your&amp;nbsp;&lt;STRONG&gt;expected result&lt;/STRONG&gt;&amp;nbsp;with backend logic and special examples. It would be helpful to find out the solution. You can refer the following link to share the required info:&lt;/P&gt;
&lt;P&gt;&lt;A href="https://nam06.safelinks.protection.outlook.com/?url=https%3A%2F%2Fcommunity.powerbi.com%2Ft5%2FCommunity-Blog%2FHow-to-provide-sample-data-in-the-Power-BI-Forum%2Fba-p%2F963216&amp;amp;data=05%7C01%7CClaire.Dong%40microsoft.com%7Cada9149bd91546a8432508dacd31ef9b%7C72f988bf86f141af91ab2d7cd011db47%7C1%7C0%7C638047911607737134%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&amp;amp;sdata=EJlYfclgtrjgAEYj9Uo1AauqxaQm3hlQsjJMo4zCY1M%3D&amp;amp;reserved=0" target="_blank" rel="noopener"&gt;How to provide sample data in the Power BI Forum&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;And&amp;nbsp;&lt;STRONG&gt;It is better&lt;/STRONG&gt;&amp;nbsp;if you can share a&amp;nbsp;&lt;STRONG&gt;simplified&lt;/STRONG&gt;&amp;nbsp;pbix file. You can refer the following link to upload the file to the community. Thank you.&lt;/P&gt;
&lt;P&gt;&lt;A href="https://nam06.safelinks.protection.outlook.com/?url=https%3A%2F%2Fcommunity.powerbi.com%2Ft5%2FDesktop%2FHow-to-upload-PBI-in-Community%2Fm-p%2F1672886&amp;amp;data=04%7C01%7Cv-yiruan%40microsoft.com%7C4f580813734d4a8355b008da16f6e91a%7C72f988bf86f141af91ab2d7cd011db47%7C1%7C0%7C637847547341062885%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C1000&amp;amp;sdata=YJvujige2YITXKbKED9JieQm5LBdf%2F3IYPM4ggdiijQ%3D&amp;amp;reserved=0" target="_blank" rel="noopener"&gt;How to upload PBI in Community&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;Thanks for your understanding. Your time and cooperation are much valued by us. We are looking forward to hearing from you to assist further.&lt;/P&gt;
&lt;P&gt;Best regards,&lt;/P&gt;
&lt;P&gt;Lucy Chen&lt;/P&gt;
&lt;P&gt;If this post &lt;STRONG&gt;&lt;EM&gt;helps&lt;/EM&gt;&lt;/STRONG&gt;, then please consider &lt;STRONG&gt;&lt;EM&gt;Accept it&lt;/EM&gt;&lt;/STRONG&gt; as the solution to help the other members find it more quickly.&lt;/P&gt;</description>
      <pubDate>Mon, 13 Jan 2025 05:27:27 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Find-cross-brand-buyers/m-p/4360717#M173102</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2025-01-13T05:27:27Z</dc:date>
    </item>
    <item>
      <title>Re: Find cross brand buyers</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Find-cross-brand-buyers/m-p/4366797#M173377</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="javascript:void(0)" data-lia-user-mentions="" data-lia-user-uid="545514" data-lia-user-login="TutanRamon" class="lia-mention lia-mention-user"&gt;TutanRamon&lt;/a&gt;&amp;nbsp;,&lt;/P&gt;
&lt;P&gt;Did the reply above offered help you solve the problem, if it helps, you can consider to accept it as a solution so that more user can refer to, or if you have other problems, you can offer some information so that can provide more suggestion for you.&lt;/P&gt;
&lt;P&gt;Best regards,&lt;/P&gt;
&lt;P&gt;Lucy Chen&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 16 Jan 2025 08:25:13 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Find-cross-brand-buyers/m-p/4366797#M173377</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2025-01-16T08:25:13Z</dc:date>
    </item>
    <item>
      <title>Re: Find cross brand buyers</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Find-cross-brand-buyers/m-p/4366931#M173380</link>
      <description>&lt;P&gt;Hi,&lt;BR /&gt;&lt;BR /&gt;Not sure what you mean with "virtual table", but if you are creating a calculated table in an import model, that is not going to work. Calculated tables are populated when the model is being processed, so it will not consider any slicers or filters.&lt;BR /&gt;So you should either be using measures or create a calculated table with all possible combinations and put that slicer on that table.&lt;/P&gt;</description>
      <pubDate>Thu, 16 Jan 2025 09:52:35 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Find-cross-brand-buyers/m-p/4366931#M173380</guid>
      <dc:creator>sjoerdvn</dc:creator>
      <dc:date>2025-01-16T09:52:35Z</dc:date>
    </item>
  </channel>
</rss>

