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

July 28 - August 9 | Final Round of the Power BI Dataviz World Championships. This is your chance. Learn more

Reply
Whitewater100
Solution Sage
Solution Sage

SQL Code

Hello:

 

I am looking to see how you would answer these two questions using SQL? Any input is appreciated! Thanks

 

Customer NameMonth & YearSales Amt
AJan-20100
BFeb-20200
Mar-20300
DApr-20400
Oct-21600
FNov-21700
GDec-21800
   
SQL Code for New Customers in 2021?

 

NameDeptID Change Null to:
anull1 hr
bfinance2  
cnull3 finance
dlogistics4  

 

1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi @Whitewater100,

As lbendlin said, your requirement seems more related to t-SQL query coding. You can post at the SQL Server forum to get better support.

In addition, you can also try to use the following follow if it helps. 

Steps:

1. Create a select query to search customer names from the raw table.

2. Add a subquery to search the customer names from the table when the year of date is less than 2021.

Subqueries (SQL Server) - SQL Server | Microsoft Docs

3. Use t-SQL 'Not IN' operator to add conditions to the main query to get customers that are not included in the subquery.

SQL NOT IN Operator (mssqltips.com)

For example:

select
    *
from
    Sales as s
where
    s.CustomerName not in (
        select
            CustomerName
        from
            Sales
        where
            Year(Sales.Date) < 2021
    )

Regards,

Xiaoxin Sheng

View solution in original post

5 REPLIES 5
Anonymous
Not applicable

Hi @Whitewater100,

As lbendlin said, your requirement seems more related to t-SQL query coding. You can post at the SQL Server forum to get better support.

In addition, you can also try to use the following follow if it helps. 

Steps:

1. Create a select query to search customer names from the raw table.

2. Add a subquery to search the customer names from the table when the year of date is less than 2021.

Subqueries (SQL Server) - SQL Server | Microsoft Docs

3. Use t-SQL 'Not IN' operator to add conditions to the main query to get customers that are not included in the subquery.

SQL NOT IN Operator (mssqltips.com)

For example:

select
    *
from
    Sales as s
where
    s.CustomerName not in (
        select
            CustomerName
        from
            Sales
        where
            Year(Sales.Date) < 2021
    )

Regards,

Xiaoxin Sheng

Thank you Xiaxin and Ibendlin for replyimg to my question. Very much appreciated!

lbendlin
Super User
Super User

you posted this in the Power BI forums?

Hi:

Do you know where I should ask this? I asked on Developer forum, on this web site. Thank you

Helpful resources

Announcements
Fabric Community Sticker Design Challenge Barcelona Carousel

Fabric Community Sticker Challenge - Barcelona 2026

If you love stickers, then you will definitely want to check out our community sticker challenge, Barcelona edition!

July Power BI Update Carousel

Power BI Monthly Update - July 2026

Check out the July 2026 Power BI update to learn about new features.

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.