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

Calling all Data Engineers! Fabric Data Engineer (Exam DP-700) live sessions are back! Starting October 16th. Sign up.

Reply
arhomberg
Helper I
Helper I

Calculated Column with Date Limits

Hello all,

 

I am attempting to create a calculated column that does a distinct count within another table. I have a subscriptions table that holds a customer id and a start and end date. There is a second table, usage, that holds the customer id, a user id, and a date for when an action was completed. I am trying to set up a column in the subscriptions table that uses the customer id in each table, filters the usage table to be greater than the start date but less than the end date in the subscriptions table, and does a distinct count of the user id’s.

 

Subscriptions

 

arhomberg_2-1682610290223.png

 

 

Usage

 

arhomberg_1-1682610199156.png

 

Result

 

arhomberg_3-1682610302832.png

 

For customer 123-456, 2 would be returned because user 'abc' and 'def' both had a record with a date between 1/1/2022 and 1/1/2023. For customer 789-101, 2 is returned because only 2 distinct users had a record in the time frame of 6/1/2022 - 6/1/2023. User 'zxy' was not within this time frame.

 

Any assistance with this would be greatly appreciated, thanks!

 

 

 

 

2 ACCEPTED SOLUTIONS
arhomberg
Helper I
Helper I

I was able to solve this with the following:

arhomberg_0-1682613093873.png

 

View solution in original post

ChrisMendoza
Resident Rockstar
Resident Rockstar

@arhomberg - This seems to work:

Column =
SUMMARIZE (
    FILTER (
        Usage,
        Usage[customer_id] = Subscriptions[customer_id]
            && Usage[date] >= Subscriptions[start_date]
            && Usage[date] <= Subscriptions[end_date]
    ),
    "@", DISTINCTCOUNT ( Usage[user_id] )
)

image.png






Did I answer your question? Mark my post as a solution!
Did my answers help arrive at a solution? Give it a kudos by clicking the Thumbs Up!

Proud to be a Super User!



View solution in original post

4 REPLIES 4
CalebR
Resolver I
Resolver I

1. Use the related function to add your start and end date into your subscriptions table.

2. Create a new calculated column in your subscriptions column to check if the salesdate is between the start and end. like this: 

Sales Within Range = IF(AND([date] >= [start_date], [date] <= [end_date]), 1, 0)
3. Then create a measure to distinctcount the userid where sales within range equals 1.
Distinct Users Within Range =
CALCULATE(
    DISTINCTCOUNT('Usage'[user_id]),
    'Usage'[Sales Within Range] = 1
)




ChrisMendoza
Resident Rockstar
Resident Rockstar

@arhomberg - This seems to work:

Column =
SUMMARIZE (
    FILTER (
        Usage,
        Usage[customer_id] = Subscriptions[customer_id]
            && Usage[date] >= Subscriptions[start_date]
            && Usage[date] <= Subscriptions[end_date]
    ),
    "@", DISTINCTCOUNT ( Usage[user_id] )
)

image.png






Did I answer your question? Mark my post as a solution!
Did my answers help arrive at a solution? Give it a kudos by clicking the Thumbs Up!

Proud to be a Super User!



Awesome, thanks @ChrisMendoza!

arhomberg
Helper I
Helper I

I was able to solve this with the following:

arhomberg_0-1682613093873.png

 

Helpful resources

Announcements
FabCon Global Hackathon Carousel

FabCon Global Hackathon

Join the Fabric FabCon Global Hackathon—running virtually through Nov 3. Open to all skill levels. $10,000 in prizes!

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