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
aukev
Helper III
Helper III

Get the initial marketing channel for a customer with multiple transactions

I`m trying to get the initial marketing channel for a customer. I have three tables which simplified are:

 

Customer

customerID

initialMarketingChannel (this is where I want the marketing channel to show)

 

Transactions

date

customerID

transactionID

GAtransactionID (there's a chance that this is 0 if no marketing data is available for this order)

 

MarketingData

date

GAtransactionID

MarketingChannel

 

All tables have many to many relationships.

 

My goal is to find the initial marketing channel for each customer (if available).

1 ACCEPTED SOLUTION

Hi @aukev ,

In your scenario, we can use the following DAX query to create a calculated table: 

Result =
ADDCOLUMNS (
    VALUES ( Transactions[customerID] ),
    "iniID", CALCULATE (
        MIN ( Transactions[GATransactionID] ),
        TOPN (
            1,
            FILTER (
                Transactions,
                Transactions[customerID] = EARLIER ( [customerID] )
                    && Transactions[GATransactionID] <> 0
            ),
            Transactions[date], ASC
        )
    )
)

Then we can create a calculated column:

initialMarketingChannel =
VAR temp =
    LOOKUPVALUE (
        MarketingData[MarketingChannel],
        MarketingData[GATransactionID], Result[iniID]
    )
RETURN
    IF ( temp = BLANK (), "None", temp )

The result will like below:

PBIDesktop_q13FfOrJwX.png

Best Regards,

Teige

View solution in original post

4 REPLIES 4
TeigeGao
Solution Sage
Solution Sage

Hi @aukev ,

Could you please share some sample data and expected result to us for analysis?

Best Regards,

Teige

Sure, thanks!

 

This is a sample of the MarketingData

dateGATransactionID
MarketingChannel
Thursday, May 2, 20191397214386Paid Search
Thursday, May 2, 20191397214390Email
Saturday, March 16, 20191397201370Paid Search
Wednesday, January 16, 20191397184884Organic
Wednesday, January 16, 20191397184778Direct
Wednesday, January 16, 20191397184822Paid Search
Wednesday, January 16, 20191397184832Organic
Wednesday, January 16, 20191397184790Paid Search
Wednesday, January 16, 20191397184986Paid Search
Wednesday, January 16, 20191397185038Paid Search
Wednesday, January 16, 20191397185050Social
Tuesday, January 15, 20191397184556Paid Search
Tuesday, January 15, 20191397184530Social
Tuesday, January 15, 20191397184520Organic
Tuesday, January 15, 20191397184768Direct
Tuesday, January 15, 20191397184766Email
Tuesday, January 15, 20191397184704Referral

 

Transactions:

datecustomerIDtransactionID
GATransactionID
01-02-2019111397214386
01-03-2019221397214390
01-04-2019331397201370
01-05-2019441397184884
01-06-2019150
01-07-2019261397184778
01-08-2019271397184822
01-09-2019481397184832
01-10-2019690
01-11-20197100
01-12-20198111397184790
01-13-20192121397184986
01-14-20199131397185038
01-15-20191141397185050
01-16-20197150
01-17-20198161397184530
01-18-20199171397184520
01-19-20196181397184768
01-20-20191191397184766
01-21-201911201397184704
01-22-20191211397184756

 

Expected Result:

customerID
initialMarketingChannel
1Paid Search
2Email
3Paid Search
4Organic
5None
6Direct
7None
8Paid Search
9Paid Search
10None
11Referral

Hi @TeigeGao , I`m still struggling with this. Any idea how best to solve this? Thanks!

Hi @aukev ,

In your scenario, we can use the following DAX query to create a calculated table: 

Result =
ADDCOLUMNS (
    VALUES ( Transactions[customerID] ),
    "iniID", CALCULATE (
        MIN ( Transactions[GATransactionID] ),
        TOPN (
            1,
            FILTER (
                Transactions,
                Transactions[customerID] = EARLIER ( [customerID] )
                    && Transactions[GATransactionID] <> 0
            ),
            Transactions[date], ASC
        )
    )
)

Then we can create a calculated column:

initialMarketingChannel =
VAR temp =
    LOOKUPVALUE (
        MarketingData[MarketingChannel],
        MarketingData[GATransactionID], Result[iniID]
    )
RETURN
    IF ( temp = BLANK (), "None", temp )

The result will like below:

PBIDesktop_q13FfOrJwX.png

Best Regards,

Teige

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.