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

Win a FREE 3 Day Ticket to FabCon Vienna. Apply now

Reply
MichaelHanksSF
New Member

Using a calculated column from a filtered table as the legend of a visualisation

Hello, I have a table ("Events") which has events data linked to individuals with IDs. Events begin on a "Commenced Date" and end on a "Ceased Date". For each event, the age of the individual at the start of the event is provided. All of this has been created in Power Query and loaded into Power BI.

 

I have a separate date table ("Date") with daily increments of days for the range of time covered by the events table. I want report users to be able to set a date range and see measures and results that are relevant for the period set.

 

For example, I have created several measures that return a single value from such filtering, such as the number of unique individuals with open events during the range:

 

 

Open Event Distinct ID Count = 
CALCULATE(
    DISTINCTCOUNT('Events'[ID]),
    FILTER(
        'Events',
        'Events'[Commenced Date] <= MAX('Date'[Date]) &&
        'Events'[Ceased Date] > MIN('Date'[Date])
        )
    ) + 0

 

 

These work just fine. However, now I want to create a visualisation that shows unique individuals by the age they were for only their most recent open event during the user-defined period.

 

If I simply use the measure above along with the age as a legend, I will get multiple counts of the same individual if they had multiple events open during the period where they were at different ages at the start.

 

I have been able to create a calculated table that provides me with the calculated column that I want, in two stages:

 

 

Date filtered events = 
CALCULATETABLE(
    'Events',
    'Events'[Commenced Date] <= MAX('Date'[Date]) &&
    'Events'[Ceased Date] > MIN('Date'[Date])
    )
Distinct ID w/ age in most recent event = 
SUMMARIZE(
    'Date filtered events',
    'Date filtered events'[ID],
    "Age at most recent event", MAX('Date filtered events'[Age])
)

 

 

For a fixed, pre-determined date range, summarising over this table provides me with the correct answer. However, it cannot be filtered by a user-defined date range and is therefore no use to me.

 

What I need is to be able to produce this as a measure somehow, with the distinct count of 'ID' per 'Age' for the given user-defined 'Date' range.

 

Can anyone help me with this, please?

 

Here is some sample data.

IDCommenced DateCeased DateAge
101/01/202015/03/20205
115/03/202025/07/20225
125/07/202212/12/20227
201/03/202025/11/202110
225/11/202115/10/202212
215/10/202213/05/202313

 

For this sample data, if a user selected a date range of 01/01/2020 - 31/12/2021, currently my visualisation for distinct count of ID with age as legend (using the measure provided above) would have underlying data:

AgeDistinct ID Count
51
101
121

 

However, I want it to have:

AgeDistinct ID Count
51
121

 

Thanks in advance!

1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi @MichaelHanksSF ,

I have created a simple sample, please refer to my pbix file to see if it helps you.

Create a date table first, then put the date column into the slicer.

Table 2 = CALENDAR(DATE(2020,1,1),DATE(2021,12,31))

Then create a measure.

Measure = var _1=MAXX(ALLSELECTED('Table 2'),'Table 2'[Date])
var _2=MINX(ALLSELECTED('Table 2'),'Table 2'[Date])
return
CALCULATE(DISTINCTCOUNT('Table'[ID]),FILTER(ALL('Table'),'Table'[Commenced Date]>=_2&&'Table'[Commenced Date]<=_1&&'Table'[Age]=SELECTEDVALUE('Table'[Age])))

vrongtiepmsft_0-1700707104678.png

 

How to Get Your Question Answered Quickly 

 

If it does not help, please provide more details with your desired output and pbix file without privacy information (or some sample data) .

 

Best Regards
Community Support Team _ Rongtie

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

 

 

 

 

View solution in original post

2 REPLIES 2
Anonymous
Not applicable

Hi @MichaelHanksSF ,

I have created a simple sample, please refer to my pbix file to see if it helps you.

Create a date table first, then put the date column into the slicer.

Table 2 = CALENDAR(DATE(2020,1,1),DATE(2021,12,31))

Then create a measure.

Measure = var _1=MAXX(ALLSELECTED('Table 2'),'Table 2'[Date])
var _2=MINX(ALLSELECTED('Table 2'),'Table 2'[Date])
return
CALCULATE(DISTINCTCOUNT('Table'[ID]),FILTER(ALL('Table'),'Table'[Commenced Date]>=_2&&'Table'[Commenced Date]<=_1&&'Table'[Age]=SELECTEDVALUE('Table'[Age])))

vrongtiepmsft_0-1700707104678.png

 

How to Get Your Question Answered Quickly 

 

If it does not help, please provide more details with your desired output and pbix file without privacy information (or some sample data) .

 

Best Regards
Community Support Team _ Rongtie

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

 

 

 

 

lbendlin
Super User
Super User

I have a separate date table ("Date") with daily increments of days for the range of time covered by the events table.

That sounds ... weird?  Wouldn't you rather have a Range slicer for that? Or better yet, educate your users on how to use the filter pane.

 

 

Helpful resources

Announcements
August Power BI Update Carousel

Power BI Monthly Update - August 2025

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

August 2025 community update carousel

Fabric Community Update - August 2025

Find out what's new and trending in the Fabric community.