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

Get inspired! Check out the entries from the Power BI DataViz World Championships preliminary rounds and give kudos to your favorites. View the vizzies.

Reply
jasonyeung87
Helper V
Helper V

Add column in table that checks for distinct records

Hi,

I have the following table structure:

distict column.JPG

 

There is a 1 to many relationship between the Ticket and Time Entries tables (related by the Ticket ID field of both tables). I want to create a new column (named Agent ID) in the Ticket table based on the following logic:

- if there is 1 distinct Responder ID for all related Time Entries, set Agent ID to the Responder ID.

- if there is more than 1 distinct Responder ID for all related Time Entries, set Agent ID to 1.

 

In the above example, tickets 1 to 3 all have 1 distinct Responder ID's, so the Agent ID is Responder ID. But ticket 4 has 2 distinct Responder ID's (56 and 67), so the Agent ID is 1.

 

I was wondering if there's a quick way to do this? Ideally it would be done within the data section of Power BI Desktop instead of Power Query Editor.

 

1 ACCEPTED SOLUTION
Ashish_Mathur
Super User
Super User

Hi,

Write this calculated column formula in the Tickets table

Column = if(CALCULATE(DISTINCTCOUNT('Time entries'[Respondent ID]),RELATEDTABLE('Time entries'))=BLANK(),BLANK(),if(CALCULATE(DISTINCTCOUNT('Time entries'[Respondent ID]),RELATEDTABLE('Time entries'))=1,Tickets[Respondent ID],1))

Hope this helps.

Untitled.png

The next time when you post a question, please share data in a format that can be pasted in an MS Excel file.  Sharing a picure is useless because the person helping you has to wast time in typing the data in MS Excel.


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/

View solution in original post

1 REPLY 1
Ashish_Mathur
Super User
Super User

Hi,

Write this calculated column formula in the Tickets table

Column = if(CALCULATE(DISTINCTCOUNT('Time entries'[Respondent ID]),RELATEDTABLE('Time entries'))=BLANK(),BLANK(),if(CALCULATE(DISTINCTCOUNT('Time entries'[Respondent ID]),RELATEDTABLE('Time entries'))=1,Tickets[Respondent ID],1))

Hope this helps.

Untitled.png

The next time when you post a question, please share data in a format that can be pasted in an MS Excel file.  Sharing a picure is useless because the person helping you has to wast time in typing the data in MS Excel.


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code FABINSIDER for a $400 discount!

FebPBI_Carousel

Power BI Monthly Update - February 2025

Check out the February 2025 Power BI update to learn about new features.

March2025 Carousel

Fabric Community Update - March 2025

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