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
Anthony_G1
Frequent Visitor

DAX Distinct on Single Column

Hello,

 

I'm struggling with trying to do something in DAX that's very easy in Power Query, however I need to do it in DAX.

 

Basically, I have a table like below:

 

COL1COL2
AAA123
AAA456
BBB789

 

I want to do a distinct based just on COL1, so the output I'm looking for is

 

COL1COL2
AAA123
BBB789

 

I tried using different combinations of FILTER, CALCULATETABLE, and DISTINCT, but everything I've tried is giving me errors. 

 

Thank you in advance to anyone who can help!

1 ACCEPTED SOLUTION
Mariusz
Community Champion
Community Champion

Hi @Anthony_G1 

 

If you need to return a table then try this.

Table 2 = 
ADDCOLUMNS(
    VALUES( 'Table'[COL1] ),
    "COL2", CALCULATE( MIN( 'Table'[COL2] ) )
)

 

Best Regards,
Mariusz

If this post helps, then please consider Accepting it as the solution.

Please feel free to connect with me.
LinkedIn

 

View solution in original post

3 REPLIES 3
Mariusz
Community Champion
Community Champion

Hi @Anthony_G1 

 

If you need to return a table then try this.

Table 2 = 
ADDCOLUMNS(
    VALUES( 'Table'[COL1] ),
    "COL2", CALCULATE( MIN( 'Table'[COL2] ) )
)

 

Best Regards,
Mariusz

If this post helps, then please consider Accepting it as the solution.

Please feel free to connect with me.
LinkedIn

 

@Mariusz 

 

Thank you Mariusz. I apologize but I should have used a better example. My table actually has five columns, and I tried extrapolating the answer you provided to generate a table that has more than the two columns but I'm unable to.

 

So if Table 1 has 

 

COL1COL2COL3COL4COL5
AAA123qwertyytipoui
AAA456asdffghjlkjh
BBB789zxcvcvbn

mnbv

 

How can I get:

 

COL1COL2COL3COL4COL5
AAA123qwertyytipoui
BBB789zxcvcvbn

mnbv

 

Thank you again for your help. Sorry again for my poor first example.

@Mariusz Sorry again but I figured it out!

 

Table 2 =
ADDCOLUMNS(
VALUES('Table'[Column1]),
"Column2", CALCULATE( MIN( 'Table'[Column2] ) ),
"Column3", CALCULATE( MIN( 'Table'[Column3] ) ),
"Column4", CALCULATE( MIN( 'Table'[Column4] ) ),
"Column5", CALCULATE( MIN( 'Table'[Column5] ) )
)
 
Thanks again!

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.

Top Solution Authors