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
Nun
Resolver I
Resolver I

New column based on distinct value

Hello,

I have the following problem. I have a table with two columns, the first contains names, the second ID.

Col1 Col2
Abc    1
Abc    2  
Cde   1
Efg     6
Hxx   7
If the col1 has more than one distinct value (Abc has ID 1 and 2), join col2 + col1, else col1
Col3 should be
1Abc
2Abc
Cde
Efg
Hxx

Thanks!

1 ACCEPTED SOLUTION

@Nun - OK, not to steal @Fowmy 's thunder here by maybe:

Column =
  VAR __Table = SUMMARIZE(FILTER('Table',[Col1]=EARLIER([Col1])),[Col2])
RETURN
  IF(COUNTROWS(__Table)>1,[Col1]&[Col2],[Col1])

Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...

View solution in original post

15 REPLIES 15
Greg_Deckler
Super User
Super User

@Nun - Not sure I completely understand, but maybe:

Column =
  IF(DISTINCTCOUNT('Table'[Col2])>1,[Col1] & [Col2],[Col1])

Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...
amitchandak
Super User
Super User

@Nun , Try a new column like

if(countx(filter(Table, [Col1] =earlier([Col1]) ),[Col1])+0 >1,[Col1]&[Col2],[Col1])

Hello,

 

thank you for the quick reply, unfortunately the output of Col3 is ID & Col1...no matter if name has an unique ID

Col3

1Abc

2Abc

1Cde

6Efg

7Hxx

the ID should be added to the name only if it unique for the col1 (name)

Thanks!

 

@Nun 

Please try this code for a new column:

Column = 
IF( COUNTROWS(FILTER(D,D[Col1]=EARLIER(D[Col1])))>1, D[Col2]&D[Col1],D[Col1])

________________________

If my answer was helpful, please consider Accept it as the solution to help the other members find it

Click on the Thumbs-Up icon if you like this reply 🙂

YouTube  LinkedIn 

Did I answer your question? Mark my post as a solution! and hit thumbs up


Subscribe and learn Power BI from these videos

Website LinkedIn PBI User Group

@Fowmy 

thanks for supporting, unfortunately I got the same results as earlier:

Col3 with ID+names instead to get a Col3 with names and only in case of two or more IDs for the same name, the output is ID+name

thanks!

@Nun 

As per your initial question, this formula shows the desired results? 

Fowmy_0-1599120150098.png

 

________________________

If my answer was helpful, please consider Accept it as the solution to help the other members find it

Click on the Thumbs-Up icon if you like this reply 🙂

YouTube  LinkedIn

 

Did I answer your question? Mark my post as a solution! and hit thumbs up


Subscribe and learn Power BI from these videos

Website LinkedIn PBI User Group

@Fowmy 

I tried your solution, as result the col3 is

11

22

33

44

..

it seems the output is a duplicate of the IDs.

 

@Nun 

Can you show me the Measure you used and the screenshot of your table?

________________________

If my answer was helpful, please consider Accept it as the solution to help the other members find it

Click on the Thumbs-Up icon if you like this reply 🙂

YouTube  LinkedIn

Did I answer your question? Mark my post as a solution! and hit thumbs up


Subscribe and learn Power BI from these videos

Website LinkedIn PBI User Group

@Fowmy 

I did a correction, now the result is all the names with the IDs. Please find enclosed the information you required. The results (Column) should print the ID only if the same name( in the previous example there is Abc twice) has more than one ID (same name but ID is 1 and 2).

measure.pngresult.pngname.pngid.png

Thanks!

@Fowmy 

an additional information that can explain the reason that your solution doesn't work with my table.

Col1 has several rows with the same name (Abc) and several rows with the same IDs

Col1     Col2

Abc       1

Abc       2

Test      3

Test       3

Test1    4

Test1    4

Test2     10

with the meausure you proposed only Test2 is printed out with only the name.

Thanks

@Nun - So what is the expected output of that last table of information that you posted? It helps to be thorough when posting sample data.


Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...

@Greg_Deckler ,

thanks for asking.

The output should be a new col. where the ID is printend out before the name only if there are several IDs for the same name. In this table:

Col1     Col2

Abc       1

Abc       2

Test      3

Test       3

Test1    4

Test1    4

Test2     10

the new col is:

Col3

1Abc

2Abc

Test

Test

Test1

Test1

Test2

Abc name is the olny value with two IDs, for that reason the output is with ID before the name.

Thank you!

@Nun - OK, not to steal @Fowmy 's thunder here by maybe:

Column =
  VAR __Table = SUMMARIZE(FILTER('Table',[Col1]=EARLIER([Col1])),[Col2])
RETURN
  IF(COUNTROWS(__Table)>1,[Col1]&[Col2],[Col1])

Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...

@Greg_Deckler 

thanks a lot!!! it works just as I wished...thank you so so much!

@Nun Sample data, expected output, works every time! 🙂


Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...

Helpful resources

Announcements
RTI Forums Carousel3

New forum boards available in Real-Time Intelligence.

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

MayPowerBICarousel1

Power BI Monthly Update - May 2024

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

Europe Fabric Conference

Europe’s largest Microsoft Fabric Community Conference

Join the community in Stockholm for expert Microsoft Fabric learning including a very exciting keynote from Arun Ulag, Corporate Vice President, Azure Data.