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

Distinct Count selected elements in a column

Hi,

 

I'm struggling with a calculated column.

 

I'd like to make a line diagram to compare 2017 - 2019 revenue trends with 2020, with the possibility to filter between 2017 - 2019.

 

So if you have all years selected, the sum of the 3 years revenue is diveded by 3, if you select two years then by 2 and if you only click on one year then by 1.

 

I wrote a measure which seems to work perfectly but when I copy it in to the calculated column it doesn't work at all.

 

It basically says: "If 2020 is part of the filter than deduct one, if it is not then count the years up to 3 (there are more years but I'm only showing 2017, 2018, 2019)

 

IF(IF(CONTAINS(FinancialData,FinancialData[Date].[Year],2020) = TRUE ,

DISTINCTCOUNT(FinancialData[Date].[Year]) - 1, DISTINCTCOUNT(FinancialData[Date].[Year]))>=3 , 3 ,IF(CONTAINS(FinancialData,FinancialData[Date].[Year],2020) = TRUE ,

DISTINCTCOUNT(FinancialData[Date].[Year]) - 1, DISTINCTCOUNT(FinancialData[Date].[Year]))))

 

Can someone help me out how to make it work in a calculated column?

 

BR,

Oliver

3 REPLIES 3
harshnathani
Community Champion
Community Champion

Greg_Deckler
Community Champion
Community Champion

@OliverMatsik Not really enough information to go on, please first check if your issue is a common issue listed here: https://community.powerbi.com/t5/Community-Blog/Before-You-Post-Read-This/ba-p/1116882

Also, please see this post regarding How to Get Your Question Answered Quickly: https://community.powerbi.com/t5/Community-Blog/How-to-Get-Your-Question-Answered-Quickly/ba-p/38490

The most important parts are:
1. Sample data as text, use the table tool in the editing bar
2. Expected output from sample data
3. Explanation in words of how to get from 1. to 2.



Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
DAX For Humans

DAX is easy, CALCULATE makes DAX hard...
amitchandak
Super User
Super User

@OliverMatsik , You can create two slicers one on depending on the date table and another on an independent date. 

From the date table, you can take distinct count of year and divide.

 

Something like this. You have use year in place of dates

https://community.powerbi.com/t5/Community-Blog/Comparing-Data-Across-Date-Ranges/ba-p/823601

 

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

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.