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

Earn a 50% discount on the DP-600 certification exam by completing the Fabric 30 Days to Learn It challenge.

Reply
Anonymous
Not applicable

Need help writing this simple logic in DAX

Heres the logic:

 

For each ContactID in ContactID column:

    Count Distinct ( ProductIDs).

Next ContactID

 

My data looks like this (well this is a mockup...):

ContactIDProductID
ID1A
ID1A
ID1A
ID1B
ID1B
ID2A
ID2B
ID2C
ID1A
ID1B

 

 

So the answer is:

ContactIDCountDistinct Values
ID12(A, B)
ID23(A, B, C)

 

A Calculated Column would look like this

 

ContactIDProductIDMy Column
ID1A2
ID1A2
ID1A2
ID1B2
ID1B2
ID2A3
ID2B3
ID2C3
ID1A2
ID1B2

 

Edit: need to use a calculated column, not a measure

 

FYI - Doing this in SSAS Tabular not Power BI, but I assume it's the same.

 

Thanks.

1 ACCEPTED SOLUTION

Then you can use this Calculated Column Formula:

My Column = CALCULATE(DISTINCTCOUNT(Table1[ProductID]),FILTER(Table1,Table1[ContactID]=EARLIER(Table1[ContactID])))

View solution in original post

5 REPLIES 5
vanessafvg
Super User
Super User

@Anonymous are you wanting your values to be concatenated ie. a,b,c?





If I took the time to answer your question and I came up with a solution, please mark my post as a solution and /or give kudos freely for the effort 🙂 Thank you!

Proud to be a Super User!




Anonymous
Not applicable

@vanessafvg No I've edited my post. I want the discinct count of productID's per each distinct contactID 

kschaefers
Resolver I
Resolver I

You could either create a measure using DISTINCTCOUNT(ColumnName) or alternatively create a new table using SUMMARIZECOLUMNS (See more details here: https://msdn.microsoft.com/en-us/library/mt163696.aspx)

Anonymous
Not applicable

@kschaefers Now that I think about, this will actually need to be a calculated column, it cannot be a separate table though. The problem is that I need separate distinct counts for each contactID. I cannot just use distinctcount(ProductID) because that would ignore the ContactID column.

Then you can use this Calculated Column Formula:

My Column = CALCULATE(DISTINCTCOUNT(Table1[ProductID]),FILTER(Table1,Table1[ContactID]=EARLIER(Table1[ContactID])))

Helpful resources

Announcements
LearnSurvey

Fabric certifications survey

Certification feedback opportunity for the community.

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.