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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
Anonymous
Not applicable

Calculated column to attribute customer based on the

Hi

 

I'm trying to solve the following problem:

 

I have two tables in my data model:

 

Dim Customer -> pink column denotes the effect I would like to achieve

 

CustomerIDCustomerEmailCustomerTypeCustomerSubType
1aaa@abc.comwholesalerB2B
2aaa@abc.comretailerB2B

 

Fact Sales

 

SaleOrderIDCustomerID
12
22
31

 

Now, I would like to create a calculated column, that in case given customer created at least one transaction as a wholesaler, will be assigned with string B2B; for all other cases (no B2B transactions or no transactions at all) it should be given B2C

 

I already tried below DAX code, but obviously it's evaluated on CustomerID level, so this customer (on the Email level) will be assigned two values (B2B and B2C)

VAR CountB2BOrders = 
CALCULATE (
DISTINCTCOUNT (SalesOrder[SalesOrderId] )
; FILTER (
SalesOrder; SalesOrder[CustomerID] =
EARLIER ( Customer[CustomerID] )
)
; Customer[CustomerType] = "wholesaler"
)

RETURN IF ( CountB2BOrders = 0; "B2C"; "B2B" )


What I need is a unified value for CustomerSubType attribute per customer email - either B2B or B2C (as presented in the first table)

 

Currently, using presented DAX formula, I'm getting multiplicated entry on the Power BI report visual for the same customer email, like:

 

CustomerEmailCustomerSubType
aaa@abc.comB2B
aaa@abc.comB2C
 

What I want to get is:

 

CustomerEmailCustomerSubType
aaa@abc.comB2B
 

 

 

 

1 REPLY 1
lbendlin
Super User
Super User

CustomerSubType =
var e=Customer[CustomerEmail]
var o=CALCULATE(count(Sales[SaleOrderID]),all(sales),Customer[CustomerEmail]=e,Customer[CustomerType]="wholesaler")
return switch (o,0,"B2C","B2B")

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.

Top Solution Authors