Don't miss your chance to take the Fabric Data Engineer (DP-600) exam for FREE! Find out how by attending the DP-600 session on April 23rd (pacific time), live or on-demand.
Learn moreNext up in the FabCon + SQLCon recap series: The roadmap for Microsoft SQL and Maximizing Developer experiences in Fabric. All sessions are available on-demand after the live show. Register now
I have a disconnected CampaignMapping table with columns (CampaignName, CustomerID, ProductCategory) where the granularity is a many-to-many combination, while Sales is at the Order/Product level related only to standard dimensions (Customers, Products, Date).
This granularity mismatch makes physical relationships impossible. How can I write a Campaign Sales measure in DAX so that selecting CampaignName on a slicer virtually filters Sales by both CustomerID and ProductCategory matches?
Solved! Go to Solution.
You can create a Campaign Sales measure by building a virtual relationship from the disconnected CampaignMapping table to Sales using TREATAS on both CustomerID and ProductCategory.
VALUES(CampaignMapping[CustomerID]) returns the distinct customers for the currently selected campaign(s).
The first TREATAS tells the engine to treat those values as if they came from Customers[CustomerID], so the row context on Sales is filtered by matching customers.
The second TREATAS does the same for ProductCategory → Products[Category], so only Sales rows where both customer and category match the campaign remain.
Because TREATAS creates a virtual relationship instead of a physical one, it works even though the CampaignMapping granularity (Campaign–Customer–Category) does not match the Sales fact granularity.
Please check the formula below:
Campaign Sales =
VAR SelectedCustomers =
VALUES ( CampaignMapping[CustomerID] )
VAR SelectedCategories =
VALUES ( CampaignMapping[ProductCategory] )
RETURN
CALCULATE (
[Total Sales],
TREATAS ( SelectedCustomers, Customers[CustomerID] ),
TREATAS ( SelectedCategories, Products[ProductCategory] )
)
Please check the formula below:
Campaign Sales =
VAR SelectedCustomers =
VALUES ( CampaignMapping[CustomerID] )
VAR SelectedCategories =
VALUES ( CampaignMapping[ProductCategory] )
RETURN
CALCULATE (
[Total Sales],
TREATAS ( SelectedCustomers, Customers[CustomerID] ),
TREATAS ( SelectedCategories, Products[ProductCategory] )
)
My advice is creating a CampaignBridge table at the same grain as Sales.
You can create a Campaign Sales measure by building a virtual relationship from the disconnected CampaignMapping table to Sales using TREATAS on both CustomerID and ProductCategory.
VALUES(CampaignMapping[CustomerID]) returns the distinct customers for the currently selected campaign(s).
The first TREATAS tells the engine to treat those values as if they came from Customers[CustomerID], so the row context on Sales is filtered by matching customers.
The second TREATAS does the same for ProductCategory → Products[Category], so only Sales rows where both customer and category match the campaign remain.
Because TREATAS creates a virtual relationship instead of a physical one, it works even though the CampaignMapping granularity (Campaign–Customer–Category) does not match the Sales fact granularity.
If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.
A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.
Share feedback directly with Fabric product managers, participate in targeted research studies and influence the Fabric roadmap.
| User | Count |
|---|---|
| 9 | |
| 6 | |
| 3 | |
| 2 | |
| 2 |
| User | Count |
|---|---|
| 21 | |
| 14 | |
| 10 | |
| 5 | |
| 5 |