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

Grow your Fabric skills and prepare for the DP-600 certification exam by completing the latest Microsoft Fabric challenge.

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
RTI Forums Carousel3

New forum boards available in Real-Time Intelligence.

Ask questions in Eventhouse and KQL, Eventstream, and Reflex.

MayPowerBICarousel

Power BI Monthly Update - May 2024

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