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

Level up your Power BI skills this month - build one visual each week and tell better stories with data! Get started

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
Solution Sage
Solution Sage

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
Solution Sage
Solution Sage

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
April Power BI Update Carousel

Power BI Monthly Update - April 2026

Check out the April 2026 Power BI update to learn about new features.

Fabric SQL PBI Data Days

Data Days 2026 coming soon!

Sign up to receive a private message when registration opens and key events begin.

New to Fabric survey Carousel

New to Fabric Survey

If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.