Forum Discussion

dakins's avatar
dakins
Helper II
3 years ago

Dax issue - Multiple conditions on date data

Hello All,


I need help with my dax. 

 

In my data set, I have:
Type - New, return, or seasonal customers
Subscription level - Gold, Silver, Bronze, Diamond
Sub - Start and End date. 

 

Goal: I'd like to calculate how many days my customer went offline before resubscribing under certain conditions.

 

Scenario - if my customer type is new or return and customer sub level is gold or bronze then calculate the end date minus the start date of my customers next purchase if the customer type is seasonal. 

Answer = 150 days 

P.s - condition - Everytime a new or returning customer subs with level gold or bronze the system automatically assigns their next type to seasonal. 

Invoice noCustomer IDTypeSub levelStart date End date
101500NewGold8/1/20228/30/2022
102601ReturnDiamond10/1/202210/1/2023
103500SeasonalDiamond03/02/202303/30/2023
104606ReturnDiamond7/31/20238/2/2023
105700RetunBronze06/1/202306/30/2023
106700SeasonalBronze11/1/202311/26/2023
107701NewDiamond04/202305/2023

 

 

For the table above the dax should calculate:

Customer 500: 8/30/2022 - 03/02/2023 = 184 days

Customer 700: 6/30/2023 - 11/1/2023 = 124 days

 

 

 

Surveillance Days =
SWITCH (
    TRUE (),
    'Customer '[Type] = "New" ||'Customer '[Type] = "Return"
    && 'Customer '[Subscription level] = "Gold" || 'Customer '[Subscription level] = "Bronze" ,
    DATEDIFF ('Sub'[Start_Date], 'Sub'[End_Date], DAY),
    'Customer '[Type]= "Seasonal",
    DATEDIFF ('Sub'[Start_Date], 'Sub'[], DAY),
    BLANK ()
)






Thank you!
D

3 Replies

  • Ahmedx, thank you.
    The dax worked using the sample data set however when tested in my live data, it didn't work as expected.
    In real world situation, customer 500 may have multiple transactions up to 5 or 6; hence the the dax has to tie every
    gold or bronze to its next seasonal sub.

    P.s - condition - Everytime a new or returning customer subs with level gold or bronze the system automatically assigns their next type to seasonal. 

    Invoice noCustomer IDTypeSub levelStart date End date
    99500NewSilver09/1/202011/1/2022
    100700NewSilver11/2/20111/20/2021
    101500NewGold8/1/20228/30/2022
    103500SeasonalDiamond03/02/202303/30/2023



  • P.S - For every seasonal customer Type, the previous sub level must be gold or bronze.