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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
MRoyW
Frequent Visitor

Distinct count over 3 columns

Hi,
I'm trying to add a new calculated column for the count of customer accounts per user (Name) in my data set.
How do I do this?
I only need the count for specific years. Like in the example table below, Kalvin would show 2 in the new column for 2020 and 1 for 2021.

NameAcc noYear
Josh1Dec23
Kalvin20Dec20
Basey3Dec21
Kalvin20Dec20
Kalvin20Dec21
2 ACCEPTED SOLUTIONS
TomMartens
Super User
Super User

Hey @MRoyW ,

 

You can use DAX statement to create a calculated column:

Column = 
var currentName = 'Table'[Name]
var currentYear = 'Table'[Year]
return
COUNTROWS(
    FILTER(
        'Table'
        , 'Table'[Name] = currentName && 'Table'[Year] = currentYear
    )
)

The table will look like this (do not wonder about the year column, this happened by pasting your data into a table):

TomMartens_0-1711607155990.png

Hopefully, this provides what you are looking for.

 

Regards,

Tom

 



Did I answer your question? Mark my post as a solution, this will help others!

Proud to be a Super User!
I accept Kudos 😉
Hamburg, Germany

View solution in original post

Shreeram04
Resolver III
Resolver III

Hi @TomMartens 

 

Please find the below measure and screenshot for your reference.

Customer Count =
CALCULATE(
    COUNTROWS('AA'),
    ALLEXCEPT('AA', 'AA'[Name], 'AA'[Year])
)


Shreeram04_0-1711607554232.png

If this post helps, then please consider Accept it as the solution 

Thanks,

Hari R

 

View solution in original post

3 REPLIES 3
MRoyW
Frequent Visitor

@TomMartens  @Shreeram04  thank you both

Shreeram04
Resolver III
Resolver III

Hi @TomMartens 

 

Please find the below measure and screenshot for your reference.

Customer Count =
CALCULATE(
    COUNTROWS('AA'),
    ALLEXCEPT('AA', 'AA'[Name], 'AA'[Year])
)


Shreeram04_0-1711607554232.png

If this post helps, then please consider Accept it as the solution 

Thanks,

Hari R

 

TomMartens
Super User
Super User

Hey @MRoyW ,

 

You can use DAX statement to create a calculated column:

Column = 
var currentName = 'Table'[Name]
var currentYear = 'Table'[Year]
return
COUNTROWS(
    FILTER(
        'Table'
        , 'Table'[Name] = currentName && 'Table'[Year] = currentYear
    )
)

The table will look like this (do not wonder about the year column, this happened by pasting your data into a table):

TomMartens_0-1711607155990.png

Hopefully, this provides what you are looking for.

 

Regards,

Tom

 



Did I answer your question? Mark my post as a solution, this will help others!

Proud to be a Super User!
I accept Kudos 😉
Hamburg, Germany

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

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

April Fabric Community Update

Fabric Community Update - April 2024

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