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
husseyma
Frequent Visitor

Distinct Count Column Based on Another Column and Within a Timeframe

I am using the below formula successfully for a calculated column that returns a unique count of names associated with each UID

 

DCount Name =
VAR ThisId = 'Transitions'[UID]
RETURN
    CALCULATE (
        DISTINCTCOUNTNOBLANK('Transitions'[Name] ),
        FILTER ( ALL ( 'Transitions' ),'Transitions'[UID] = ThisId)
    )
 
The problem is that I would like to somehow modify the formula so it takes into account my date slicers. At present I am getting the same count irrespective of changing my date slicers because the formula does not take date into account. There is a date column within the "Transitions" table and I have a separate DateDim table also.
 
Ultimately I would like to be able to build a rolling 12 month count of the basis of this data.
Any pointers, greatly appreciated.
 
Thank you!
2 REPLIES 2
rajendraongole1
Super User
Super User

Hi @husseyma - To make your calculated column respond to date slicers, you'll need to modify the formula so that it includes the date context.

DCount Name =
VAR ThisId = 'Transitions'[UID]
VAR SelectedDateRange = CALCULATETABLE(
VALUES('DateDim'[Date]),
ALLSELECTED('DateDim')
)
RETURN
CALCULATE(
DISTINCTCOUNTNOBLANK('Transitions'[Name]),
FILTER(
ALL('Transitions'),
'Transitions'[UID] = ThisId &&
'Transitions'[Date] IN SelectedDateRange
)
)

 

create a measure instead of a calculated column since measures are more dynamic

Rolling 12M DCount Name =
VAR EndDate = MAX('DateDim'[Date])
VAR StartDate = EDATE(EndDate, -12)
RETURN
CALCULATE(
DISTINCTCOUNTNOBLANK('Transitions'[Name]),
FILTER(
ALL('Transitions'),
'Transitions'[UID] = MAX('Transitions'[UID]) &&
'Transitions'[Date] >= StartDate &&
'Transitions'[Date] <= EndDate
)
)

 

Hope it works in your scenerio





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!





Thank you so much for your response, unfortunately the modified formula suggested still returns the same result as the original calculation, ie it ignores my date slicers and displays a count for the entire table.  The Rolling 12M also does not appear to be returning relevant results...

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!

October Power BI Update Carousel

Power BI Monthly Update - October 2025

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

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.