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

Vote for your favorite vizzies from the Power BI Dataviz World Championship submissions. Vote now!

Reply
Ar_Sh
Advocate II
Advocate II

Need Help

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?

2 ACCEPTED SOLUTIONS
Shubham_rai955
Super User
Super User

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.

1. Base measure

 
Sales Amount := SUM ( Sales[Amount] )

2. Campaign Sales measure using TREATAS

 
Campaign Sales := CALCULATE ( [Sales Amount], TREATAS ( VALUES ( CampaignMapping[CustomerID] ), Customers[CustomerID] ), TREATAS ( VALUES ( CampaignMapping[ProductCategory] ), Products[Category] ) )

3. Explanation 

  • 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.

View solution in original post

cengizhanarslan
Super User
Super User

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] )
)
_________________________________________________________
If this helped, ✓ Mark as Solution | Kudos appreciated
Connect on LinkedIn
AI-assisted tools are used solely for wording support. All conclusions are independently reviewed.

View solution in original post

3 REPLIES 3
cengizhanarslan
Super User
Super User

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] )
)
_________________________________________________________
If this helped, ✓ Mark as Solution | Kudos appreciated
Connect on LinkedIn
AI-assisted tools are used solely for wording support. All conclusions are independently reviewed.
anilelmastasi
Super User
Super User

My advice is creating a CampaignBridge table at the same grain as Sales.

 

Shubham_rai955
Super User
Super User

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.

1. Base measure

 
Sales Amount := SUM ( Sales[Amount] )

2. Campaign Sales measure using TREATAS

 
Campaign Sales := CALCULATE ( [Sales Amount], TREATAS ( VALUES ( CampaignMapping[CustomerID] ), Customers[CustomerID] ), TREATAS ( VALUES ( CampaignMapping[ProductCategory] ), Products[Category] ) )

3. Explanation 

  • 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.

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

Vote for your favorite vizzies from the Power BI World Championship submissions!

Sticker Challenge 2026 Carousel

Join our Community Sticker Challenge 2026

If you love stickers, then you will definitely want to check out our Community Sticker Challenge!

January Power BI Update Carousel

Power BI Monthly Update - January 2026

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