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

July 7 - July 17 | Round 2 of the Power BI Dataviz World Championships. Don't miss your chance! Learn more

Reply
BalajiBuddha
Frequent Visitor

Native SQL query for Power BI

HI Everyone,

i want to filter out few things here 

1. for reporting period <=2026-03 i should show all data 

2. for reporting period >= 2026-04, for ssid - kunshan and takahama i should exclude few countries and for remaining SSID i should show all countires

Native SQL query for Power BI

Thanks,
Balaji.

 

1 ACCEPTED SOLUTION

Hi @BalajiBuddha 
Hi,
There are two approaches you can use — pick whichever fits your setup better:
Option 1: Native SQL Query inside Power BI Advanced Editor
Pass the full SQL logic directly in M code so the filtering happens at the source before data loads into Power BI:

let
    SqlQuery =
        "SELECT *
        FROM ""your_schema"".""your_table""
        WHERE
            reporting_period <= '2026-03'
            OR
            (
                reporting_period >= '2026-04'
                AND (
                    (
                        ssid IN ('Kunshan', 'Takahama')
                        AND country NOT IN ('Country1', 'Country2', 'Country3')
                    )
                    OR ssid NOT IN ('Kunshan', 'Takahama')
                )
            )",

    Source = Snowflake.Databases("your_server","your_warehouse"),
    DB = Source{[Name="your_database"]}[Data],
    Schema = DB{[Name="your_schema"]}[Data],
    Result = Value.NativeQuery(Schema, SqlQuery)

in
    Result

 

Option 2:  Create a View in Snowflake (Recommended if you have access)
 This way every report using this dataset inherits the rules automatically with no changes needed in Power BI:

 

If this response was helpful, please accept it as a solution and give kudos to support other community members

 

 

View solution in original post

6 REPLIES 6
v-priyankata
Community Support
Community Support

Hi @BalajiBuddha 

Thank you for reaching out to the Microsoft Fabric Forum Community.

@SharmilaBrisca @ArwaAldoud Thanks for the inputs.

I hope the information provided by users was helpful. If you still have questions, please don't hesitate to reach out to the community.

 

Hi @BalajiBuddha 

Hope everything’s going smoothly on your end. I wanted to check if the issue got sorted. if you have any other issues please reach community.

SharmilaBrisca
Resolver I
Resolver I

Hi @BalajiBuddha,

If your database is sql server try the below query,

SELECT *

FROM YourTable

WHERE

    CONVERT(DATE, ReportingPeriod + '-01') <= '2026-03-01'

    OR

    (

        CONVERT(DATE, ReportingPeriod + '-01') >= '2026-04-01'

        AND

        (

            (

                SSID IN ('Kunshan', 'Takahama')

                AND Country NOT IN ('Country1', 'Country2')

            )

            OR

            SSID NOT IN ('Kunshan', 'Takahama')

        )

    )

 

Thanks and Regards

GainInsights Solutions

Trusted Microsoft Partner - https://gain-insights.com/partnerships/microsoft/
www.gain-insights.com

HI ,

we are using snowflake but user asking us to do the changes in the dataset so , all related reports will effect , so i want this changes in dataset.


Hi @BalajiBuddha 
Hi,
There are two approaches you can use — pick whichever fits your setup better:
Option 1: Native SQL Query inside Power BI Advanced Editor
Pass the full SQL logic directly in M code so the filtering happens at the source before data loads into Power BI:

let
    SqlQuery =
        "SELECT *
        FROM ""your_schema"".""your_table""
        WHERE
            reporting_period <= '2026-03'
            OR
            (
                reporting_period >= '2026-04'
                AND (
                    (
                        ssid IN ('Kunshan', 'Takahama')
                        AND country NOT IN ('Country1', 'Country2', 'Country3')
                    )
                    OR ssid NOT IN ('Kunshan', 'Takahama')
                )
            )",

    Source = Snowflake.Databases("your_server","your_warehouse"),
    DB = Source{[Name="your_database"]}[Data],
    Schema = DB{[Name="your_schema"]}[Data],
    Result = Value.NativeQuery(Schema, SqlQuery)

in
    Result

 

Option 2:  Create a View in Snowflake (Recommended if you have access)
 This way every report using this dataset inherits the rules automatically with no changes needed in Power BI:

 

If this response was helpful, please accept it as a solution and give kudos to support other community members

 

 

SharmilaBrisca
Resolver I
Resolver I

Hi @BalajiBuddha,

 

What database are you using?

Helpful resources

Announcements
FabCon and SQLCon Barcelona 2026

FabCon & SQLCon – Barcelona 2026

Join us in Barcelona for FabCon and SQLCon, the Fabric, Power BI, SQL, and AI community event. Save €200 with code FABCMTY200.

60 days of Data Days Carousel

Data Days 2026

Join Data Days 2026: 60 days of free live/on-demand sessions, challenges, study groups, and certification opportunities.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.