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

Don't miss out! 2025 Microsoft Fabric Community Conference, March 31 - April 2, Las Vegas, Nevada. Use code MSCUST for a $150 discount. Prices go up February 11th. Register now.

Reply
beckyconning
Helper I
Helper I

Best way to filter records by a separate grouping than is used in charts and tables

In SQL (this sample is Snowflake dialect but it could be easily modified for T-SQL) I would do this (although perhaps there is a better way).

 

select * from adverse_drug_reactions as reports right join (select count(distinct drug) = 1 or count(distinct reaction) = 1 as valid, report_id from adverse_drug_reactions group by report_id having not valid) as valid_reports on reports.report_id = valid_reports.report_id;

 

 

I could do the equivilant using the Power Query Editor and "Merge Queries" however I'm wondering if there is a preferable way of doing this in Power BI.

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

HI @beckyconning ,

I'd like to suggest you expand 'advanced option' on SQL connector and copy your code to t-sql statement to get a merged table instead of getting multiple tables and merge them on power query side.

Connect-Power-BI-to-SQL-Server-5

Regards,

Xiaoxin Sheng

Community Support Team _ Xiaoxin
If this post helps, please consider accept as solution to help other members find it more quickly.

View solution in original post

2 REPLIES 2
v-shex-msft
Community Support
Community Support

HI @beckyconning ,

I'd like to suggest you expand 'advanced option' on SQL connector and copy your code to t-sql statement to get a merged table instead of getting multiple tables and merge them on power query side.

Connect-Power-BI-to-SQL-Server-5

Regards,

Xiaoxin Sheng

Community Support Team _ Xiaoxin
If this post helps, please consider accept as solution to help other members find it more quickly.
beckyconning
Helper I
Helper I

Essentially I want to filter out records assoicated with more than one reaction or more than one drug.

Records assoicated with reports that contain more than one reaction but only a single drug should be included.

Records associated with reports that contain more than one drug but only a single reaction should be included.
Records with a single drug and a single reaction should be included.

Other records should be filtered away.

 

Each row is a potential reaction to a drug e.g.

 

 

 

REPORT_ID,DRUG,REACTION,DRUG_CHARACTERIZATION_CODE,DRUG_CLASS,DRUG_INDICATION
10004519,OXYCONTIN (NDA 22-272),Osteopenia,1,NULL,OSTEOARTHRITIS
10004519,OXYCONTIN (NDA 22-272),Osteoporosis,1,NULL,OSTEOARTHRITIS

 

 

 

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 MSCUST for a $150 discount!

Jan25PBI_Carousel

Power BI Monthly Update - January 2025

Check out the January 2025 Power BI update to learn about new features in Reporting, Modeling, and Data Connectivity.

Jan NL Carousel

Fabric Community Update - January 2025

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