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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
sflaming
Frequent Visitor

Count the number of years a contact has donated

I am trying to create a measure which will count the number of years that a contact has given a donation. 

 

For example, using the sample data below (which is linked by Contact ID, and the date recieved is linked to a calendar dimension date table), I would like the output of the measure/column to be 3 for Sarah John (she contributed in 3 different years), 4 for Tom Kim, etc. 

 

Any thoughts?

 

Contact IDDisplay Name
45Sarah John
102Tom Kim
845Rebecca Firsk

 

ContactIDDisplay NameDate ReceivedSoft Credit Amount
45Sarah John11/15/2020 0:00150
45Sarah John12/20/2020 0:0060
102Tom Kim12/24/2020 0:0062.5
102Tom Kim2/5/2021 0:0020
845Rebecca Firsk3/6/2021 0:0025
845Rebecca Firsk5/18/2021 0:008.34
45Sarah John10/14/2021 0:0020.84
845Rebecca Firsk3/4/2022 0:0020
845Rebecca Firsk3/7/2022 0:0050
45Sarah John6/30/2022 0:00100
102Tom Kim8/23/2022 0:0025
845Rebecca Firsk12/28/2022 0:00150
102Tom Kim4/20/2023 0:00

28

1 ACCEPTED SOLUTION
barritown
Super User
Super User

Hi @sflaming,

If your Calendar table has a bi-directional cross filtering with the fact table and you have the [Year] column in it:

barritown_0-1689327377150.png

the measure may be as simple as that: 

barritown_1-1689327442898.png

Best Regards,

Alexander

My YouTube vlog in English

My YouTube vlog in Russian

View solution in original post

4 REPLIES 4
sflaming
Frequent Visitor

@barritown I ended up adding a column to my calendar dimension table called "Year", and then created a measure 

Number Of Years = DISTINCTCOUNT(DimDate[Year]) that works! 
 
Not sure why I couldn't use the 'Year' from the date hierarchy here, but happy to have it working now!
sflaming
Frequent Visitor

@barritown thank you! When I try that, I am getting a count of all years. Is that because I have a many to one relationship here? I made the relationship bidirectional. Here's my model:

 

sflaming_0-1689342211846.png

 

@sflaming, no, one-to-many shouldn't spoil it. There is something else, I guess. 

You can try such an alternative, which is heavier and slower (and ignores the fact that you have a calendar table) but may work:

barritown_0-1689344563445.png

In plain text:

 

Measure 2 = 
VAR _tbl = SUMMARIZE ( ADDCOLUMNS ( Donations, "Year", YEAR ( [Date Received] ) ), [ContactID], [Year] )
RETURN COUNTROWS ( _tbl )  

 

Best Regards,

Alexander

My YouTube vlog in English

My YouTube vlog in Russian

barritown
Super User
Super User

Hi @sflaming,

If your Calendar table has a bi-directional cross filtering with the fact table and you have the [Year] column in it:

barritown_0-1689327377150.png

the measure may be as simple as that: 

barritown_1-1689327442898.png

Best Regards,

Alexander

My YouTube vlog in English

My YouTube vlog in Russian

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

December 2025 Power BI Update Carousel

Power BI Monthly Update - December 2025

Check out the December 2025 Power BI Holiday Recap!

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.