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

Get Fabric Certified for FREE during Fabric Data Days. Don't miss your chance! Request now

Reply
joyhackett
Helper II
Helper II

Days between Start Date and previous record End Date

Hi,

I have a contract model much like this simplified example:

dim_user

user_id
1


fact_user_contract_history

user_idtypestartendprevious statuscurrent status
1A5/1/20215/15/2021inactiveactive
1B5/15/20215/31/2021activeactive
1B5/31/2021 activeinactive
1C2/18/2022 inactiveactive

 

Filters:

  • date range (dim_date[full_date])
  • type (dim_type[type])

 

For the contracts that have current status = active, I would like an "Activation Type" measure on each row that says if the row is the user's first contract ("New"), renewal contract (no gap in time = "Renew"), or a rejoin (a gap in time = "Rejoin").

 

 

user_iduser_indextypestartendprevious statuscurrent statusActivation Type
11A5/1/20215/15/2021inactiveactiveNEW
12B5/15/20215/31/2021activeactiveRENEW
13B5/31/2021 activeinactive 
14C2/18/2022 inactiveactiveREJOIN

 

Unfortunately, the easy way of making this a calculated column is not possible in my case because when a type filter is applied, the Activation Type may change. Example (type = C only)

user_iduser_indextypestartendprevious statuscurrent statusActivation Type
14C2/18/2022 inactiveactiveNEW

 

I have a measure that counts "NEW", but haven't figured out how to create an "Activation Type" which I can use to get the counts.

 

Thanks in advance for any guidance!!

 

First Active Date =
CALCULATE(
MIN(fact_user_contract_history[start date]), ALLEXCEPT( dim_user,dim_user_current[user_id]),
FILTER(fact_user_contract_history, fact_user_contract_history[current status] = "Active")
)
Count of New =
CALCULATE(
COUNTROWS(dim_user),
FILTER(dim_user, [First Active Contract Date] >= MIN(dim_date[full_date])
&&
[First Active Membership Date] <= MAX(dim_date[full_date]))
)
 
3 REPLIES 3
joyhackett
Helper II
Helper II

Thanks, that wasn't it, but it gave me an idea.

 

I added a column active_index to the fact table, so the contracts are indexed within each user group. This allows me to create a measure:

 

DaysBetweenActive=

//get active_index for current record
VAR
IndexNum = CALCULATE(
MAX(fact_user_contract_history[active_index] ))

//get end date of previous record 
VAR PreviousActiveDate = CALCULATE(
MAX(fact_user_contract_history[end]),
FILTER ( ALLSELECTED(fact_user_contract_history), fact_user_contract_history[active_index] = IndexNum - 1)

//calculate days between current record start date and previous record end date
RETURN
DATEDIFF(_PreviousActiveEndDate,MIN(fact_user_contract_history[start]),DAY)

The results are correct. However, I'm still unable to assign an Activation Type value:
joyhackett_0-1647529191353.png

I tried a SWITCH measure, but when I add that to the table, the records duplicate over and over...




Hi @joyhackett 

 

How did you write the SWITCH measure? Maybe you can try this one

Activation Type =
SWITCH (
    TRUE (),
    [DaysBetweenActive] < 0, "NEW",
    [DaysBetweenActive] = 0, "RENEW",
    "REJOIN"
)

 

Best Regards,
Community Support Team _ Jing
If this post helps, please Accept it as Solution to help other members find it.

amitchandak
Super User
Super User

@joyhackett , try a measure like

 

Measure =
VAR __id = MAX ('Table'[user_id] )
VAR __date = CALCULATE ( Min('Table'[start] ), ALLSELECTED ('Table' ), 'Table'[user_id] = __id )
return
CALCULATE ( Countrows ('Table' ), VALUES ('Table'[user_id] ),'Table'[user_id] = __id,'Table'[start] = __date )

 

 

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

Helpful resources

Announcements
November Power BI Update Carousel

Power BI Monthly Update - November 2025

Check out the November 2025 Power BI update to learn about new features.

Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

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.

Top Solution Authors
Top Kudoed Authors