SQL Python PowerBI Questions and Answers
SQL Python PowerBI Questions and Answers
4. Data Partitioning
Partitioning in SQL improves query performance by dividing large tables into smaller, more
manageable pieces based on a key column, typically time or categorical data. This allows for
more efficient data retrieval and query optimization. Example:
CREATE TABLE Orders (
OrderID INT,
OrderDate DATE,
OrderValue DECIMAL(10, 2)
)
PARTITION BY RANGE (YEAR(OrderDate));
5. Recursive Queries
Query:
WITH EmployeeHierarchy AS (
SELECT EmployeeID, ManagerID, Department
FROM Employees
WHERE ManagerID IS NULL
UNION ALL
SELECT e.EmployeeID, e.ManagerID, e.Department
FROM Employees e
INNER JOIN EmployeeHierarchy eh ON e.ManagerID = eh.EmployeeID
)
SELECT * FROM EmployeeHierarchy;
Python Questions
def clean_data(df):
# Remove duplicates
df = df.drop_duplicates()
# Handle missing values
df = df.fillna(method='ffill')
# Standardize column names
df.columns = df.columns.str.lower().str.replace(' ', '_')
return df
def analyze_sentiment(review):
blob = TextBlob(review)
return blob.sentiment.polarity
df = pd.read_csv('customer_reviews.csv')
df['sentiment'] = df['review'].apply(analyze_sentiment)
3. Data Sampling
To create a stratified sample ensuring key category proportions are maintained:
import pandas as pd
4. Parallel Processing
Python program for parallel processing using multiprocessing:
import multiprocessing
def process_data(data):
return data * 2
if __name__ == '__main__':
data = [1, 2, 3, 4, 5]
with multiprocessing.Pool(processes=4) as pool:
results = pool.map(process_data, data)
print(results)
Advantages: Parallel processing reduces the overall execution time by utilizing multiple CPU
cores.
5. Database Interaction
Python script to connect to MySQL and save data into Excel:
import mysql.connector
import pandas as pd
def fetch_data_from_db():
conn = mysql.connector.connect(
host='localhost',
user='root',
password='password',
database='mydb'
)
query = 'SELECT * FROM table_name'
df = pd.read_sql(query, conn)
df.to_excel('output.xlsx', index=False)
conn.close()
Power BI Questions
2. Parameterized Reports
To create parameterized reports in Power BI, you can use parameters to filter data based on
user input. These parameters can be used in query filters or DAX measures to customize
report results, such as date ranges or regions.
5. Gateway Configuration
To configure an On-Premises Data Gateway in Power BI, download and install the gateway
on a server, configure it with your Power BI account, and connect to your on-premises data
sources. Troubleshooting connectivity issues often involves checking network/firewall
settings or reconfiguring the gateway to resolve connectivity problems.