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
akfir
Helper V
Helper V

Finding customer status for a given date

Hi Masters,
Given is a table of status changes of customers (Old Status, New Status, Change Date, Previous Change Date) as described:

akfir_1-1675578334731.png

Also given is the column "First Purchase Date" which is constant for each Customer ID.
I wish to add a calculated column which will return the customer status of each customer while his first purchase.
in the example above, customer 123 first purchase date is 15/01/2022. therefore, according to his status changes dates his status while first purchase was "b" (15/1/2022 is between 01/01/2022 and 01/02/2022)

thanks for helping out.
Amit

1 ACCEPTED SOLUTION

hi @akfir 

then try like:

StatusWhileFirstPurhcase2 = 
VAR _customer = [CustomerID]
VAR _firstdate = [FirstPurchaseDate]
VAR _value1 = 
MAXX(
    FILTER(
        TableName,
        TableName[CustomerID]=_customer
            &&TableName[StatusChangeDate]>=_firstdate
            &&TableName[PreviousChangeDate]<=_firstdate
    ),
    TableName[OldStatus]
)
VAR _value2 =
MAXX(
    TOPN(
        1,
        FILTER(
            TableName,
            TableName[CustomerID]=_customer
        ),
        TableName[StatusChangeDate]
    ),
    TableName[NewStatus]
)
RETURN
IF( _value1<>BLANK(), _value1,  _value2 )

 

FreemanZ_1-1675586165945.png

View solution in original post

6 REPLIES 6
FreemanZ
Super User
Super User

hi @akfir 

try to add a column like:

StatusWhileFirstPurhcase2 = 
VAR _customer = [CustomerID]
VAR _firstdate = [FirstPurchaseDate]
RETURN
MAXX(
    FILTER(
        TableName,
        TableName[CustomerID]=_customer
            &&TableName[StatusChangeDate]>=_firstdate
            &&TableName[PreviousChangeDate]<=_firstdate
    ),
    TableName[OldStatus]
)

 

i worked like:

FreemanZ_0-1675580929211.png

 

thanks for your quick reply!
it seems good but fail to show values in cases where FIRST PURCHASE DATE is larger than any status change date and then it returns BLANK instead of i guess NEW Status

hi @akfir 

could you enrich your sample data and let us see how it works?

yes please.

akfir_0-1675584374011.png

have a look in customer 456. First Purchase Date is later than latest Status change date. therefore value should be "d"

hi @akfir 

then try like:

StatusWhileFirstPurhcase2 = 
VAR _customer = [CustomerID]
VAR _firstdate = [FirstPurchaseDate]
VAR _value1 = 
MAXX(
    FILTER(
        TableName,
        TableName[CustomerID]=_customer
            &&TableName[StatusChangeDate]>=_firstdate
            &&TableName[PreviousChangeDate]<=_firstdate
    ),
    TableName[OldStatus]
)
VAR _value2 =
MAXX(
    TOPN(
        1,
        FILTER(
            TableName,
            TableName[CustomerID]=_customer
        ),
        TableName[StatusChangeDate]
    ),
    TableName[NewStatus]
)
RETURN
IF( _value1<>BLANK(), _value1,  _value2 )

 

FreemanZ_1-1675586165945.png

Perfect thanks!

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