Forum Discussion

OliverMatsik's avatar
OliverMatsik
Frequent Visitor
6 years ago

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