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
GabrielVan
New Member

How to filter rows with IN operator on subquery that uses GROUP BY HAVING COUNT(*) > 1 (SQL to DAX)

Dear fellow developers,

 

I am quite new to DAX, but familiar with SQL. So I would like to explain what I want to achieve in DAX, using an SQL example:

 

SELECT col1, col2, col3

FROM table1

WHERE col1 IN

(SELECT col1

  FROM table1

  GROUP BY col1

  HAVING COUNT(*) > 1)

 

Thanks in advance!

 

 

1 ACCEPTED SOLUTION
v-binbinyu-msft
Community Support
Community Support

Hi @GabrielVan ,

Please try below steps

1.my test table

Table:

vbinbinyumsft_0-1661491925661.png

2. create a new table by below dax formula

Table 2 =
VAR tmp =
    CALCULATETABLE (
        VALUES ( 'Table'[Col1] ),
        FILTER (
            SUMMARIZE ( 'Table', 'Table'[Col1], "Count_Rows", COUNT ( 'Table'[Col2] ) ),
            [Count_Rows] > 1
        )
    )
RETURN
    FILTER ( 'Table', 'Table'[Col1] IN tmp )

vbinbinyumsft_1-1661492049750.png

Please refer the attached .pbix file.

 

Best regards,
Community Support Team_ Binbin Yu
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

 

View solution in original post

3 REPLIES 3
v-binbinyu-msft
Community Support
Community Support

Hi @GabrielVan ,

Please try below steps

1.my test table

Table:

vbinbinyumsft_0-1661491925661.png

2. create a new table by below dax formula

Table 2 =
VAR tmp =
    CALCULATETABLE (
        VALUES ( 'Table'[Col1] ),
        FILTER (
            SUMMARIZE ( 'Table', 'Table'[Col1], "Count_Rows", COUNT ( 'Table'[Col2] ) ),
            [Count_Rows] > 1
        )
    )
RETURN
    FILTER ( 'Table', 'Table'[Col1] IN tmp )

vbinbinyumsft_1-1661492049750.png

Please refer the attached .pbix file.

 

Best regards,
Community Support Team_ Binbin Yu
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

 

Jihwan_Kim
Super User
Super User

Hi,

I am not sure if I understood your question correctly, but I tried to create a sample pbix file like the attached.

I hope the attached file can provide some ideas on how to create a solution for your dataset.

 

If this post helps, then please consider accepting it as the solution to help other members find it faster, and give a big thumbs up.


Go to My LinkedIn Page


Thank you Jihwan Kim!

Helpful resources

Announcements
LearnSurvey

Fabric certifications survey

Certification feedback opportunity for the community.

Top Solution Authors