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
Abhaykumar
Employee
Employee

Getting distinct values for multiple columns

Is there a way to get distinct values for multiple columns? Specifically, I want to replicate the following SQL query into PowerBI to create a new table:

 

SELECT DISTINCT Col1, Col2, Col3 FROM TableA;

I can find the DISTINCT keyword, but it only supports one column. 

 

 

2 ACCEPTED SOLUTIONS
ankitpatira
Community Champion
Community Champion

@Abhaykumar You can also select individual columns in query editor and click Remove Duplicates.

 

Capture.PNG

View solution in original post

achinm45
Advocate IV
Advocate IV

Hi @Abhaykumar,

 

Use DAX and in DAX the function SUMMARIZE().

Summarize will pull out distinct values from columns.

 

So your resultset will be new table from Summarize

Table_Output =  Summarize(Table_IN,Col1,Col2,Col3)

 

I hope it helps !

 

BR,

Achin

View solution in original post

31 REPLIES 31
ToFrai
Frequent Visitor

Hi Imke,

thanks for the hint - where do I enter the code in the querie editor? Do I have to create a new table first, or add a new step in an existing query?

 

Problem is that the querie editor shows source tables only, not the ones I caclulated.

Isn't there a Dax formula that I can use in a new table that says something like "copy all (distinct) values from Table A Column 1, and then below all (distinct) valies from Table 2 Column 1, ...."?

 

BR | Tobias

You CAN do it in your current query:

Add step manually by clicking the fx-sign:

 image.png

 

But of course, this only works for tables that exist in the query editor.

If you've created them in the data view with DAX, then you won't have access to them there.

 

You might consider opening a new thread and specifically request a DAX-solution to enhance visibility of your request.

Imke Feldmann (The BIccountant)

If you liked my solution, please give it a thumbs up. And if I did answer your question, please mark this post as a solution. Thanks!

How to integrate M-code into your solution -- How to get your questions answered quickly -- How to provide sample data -- Check out more PBI- learning resources here -- Performance Tipps for M-queries

ankitpatira
Community Champion
Community Champion

@Abhaykumar You can also select individual columns in query editor and click Remove Duplicates.

 

Capture.PNG

Anonymous
Not applicable

@ankitpatira if he reomves the duplicates will it not remove the entire row ? which will ultimately result in wrong data ?

i am new to powerBI

My anser was rubbish (it would create a list of distinct values of the selected columns and returns it as a list if applied as a standalone-command (and not within a Table.AddColumn-command where will be performed as a function acting on record-level)).

 

Do as @ankitpatira said in the query-editor: First select the columns with your mouse and then click as shown. No need to edit a formula then 🙂

Imke Feldmann (The BIccountant)

If you liked my solution, please give it a thumbs up. And if I did answer your question, please mark this post as a solution. Thanks!

How to integrate M-code into your solution -- How to get your questions answered quickly -- How to provide sample data -- Check out more PBI- learning resources here -- Performance Tipps for M-queries

Greg_Deckler
Super User
Super User

In DAX, you could use:

 

Column = CONCATENATE(CONCATENATE([Col1],[Col2]),[Col3])

Then you could use DISTINCTCOUNT and such on that Column. Or, just put [Column] in a table/matrix and it will only show the distinct values.


@ 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...
ImkeF
Super User
Super User

So you have to turn your multiple columns into one list first.

List.Distinct(List.Union({Source[Col1], Source[Col2], Source[Col3]}))

Where "Source" is the name of the table/previous step 

Imke Feldmann (The BIccountant)

If you liked my solution, please give it a thumbs up. And if I did answer your question, please mark this post as a solution. Thanks!

How to integrate M-code into your solution -- How to get your questions answered quickly -- How to provide sample data -- Check out more PBI- learning resources here -- Performance Tipps for M-queries

ilamp
Frequent Visitor

Thank you. Exactly what I needed. 

Thanks Imke for your reply. However I am getting the following error :

2016-04-28 16_20_45-Error.jpg

The expression is for creating a new table in Data view.

The error says :

A single value for column 'BlobName' in table 'ProdBlobInfo-Final' cannot be determined. This can happen when a measure formula refers to a column that contains many values without specifying an aggregation such as min, max, count, or sum to get a single result.

Sorry, should have mentioned that you need to add this column in the query editor, it's M-code.

Imke Feldmann (The BIccountant)

If you liked my solution, please give it a thumbs up. And if I did answer your question, please mark this post as a solution. Thanks!

How to integrate M-code into your solution -- How to get your questions answered quickly -- How to provide sample data -- Check out more PBI- learning resources here -- Performance Tipps for M-queries

I tried to create a custom column using Query Editor. The column gets created as a List but gives error when expanded.

 

2016-04-28 16_51_56-Error1.jpg2016-04-28 16_52_47-Error2.jpg2016-04-28 16_53_07-Error3.jpg

 

Let me know if i am doing something wrong.

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.