Transforming Data with Microsoft Fabric: A Step-by-Step Guide for Beginners

Linda Olela
7 min readAug 11, 2024

Data transformation is a critical step in turning raw information into actionable insights. If you’re exploring Microsoft Fabric as your go-to-solution, you’re in for a powerful, yet user-friendly experience and you have come to the right place. Microsoft Fabric offers a comprehensive suite of tools that cater to every step of the data transformation process, from cleaning and enriching data to building sophisticated models that can drive meaningful insights.

In this post, I’ll walk you through my experience with Microsoft Fabric, detailing how I used tools like Dataflows Gen 2, Lakehouse, SQL endpoints, and Spark Notebooks to tackle real-world data challenges, particularly when it comes to data transformation. Whether you’re a beginner or an intermediate user, this guide will help you understand how to leverage Microsoft Fabric’s capabilities for your own projects.

Getting Started: Understanding Microsoft Fabric

Microsoft Fabric is an integrated platform designed to handle complex data operations across various stages — cleaning, enrichment, and modeling. It seamlessly brings together tools like Azure Synapse, Power BI, and Databricks under one umbrella, making it easier for data professionals to manage the entire data pipeline without needing to switch between different environments.

For my data transformation project, I worked with the following key components:

  1. Dataflows Gen 2: A cloud-based tool for ingesting, transforming, and loading data. It’s particularly useful for cleaning and pre-processing data.
  2. Lakehouse: A unified data architecture that combines the best of data lakes and data warehouses. It supports structured, semi-structured, and unstructured data.
  3. SQL Endpoints: These allow for querying data using T-SQL, making it easier to work with relational data stored in the Lakehouse.
  4. Spark Notebooks: A powerful tool for executing large-scale data processing tasks using Apache Spark, ideal for complex transformations and machine learning tasks.
  5. Power Query: A versatile data connection technology that enables users to discover, connect, and refine data across a wide variety of sources.

Now, let’s get started with how to use these tools to transform raw data into actionable insights.

Step 1: Data Cleaning — Laying the Foundation

The first step in any data transformation journey is cleaning the data. Without clean data, any analysis you perform downstream will be unreliable. In Microsoft Fabric, Dataflows Gen 2 is a game-changer when it comes to data cleaning. It provides a visual interface where you can easily apply transformations, identify issues, and fix them on the spot.

Key Tasks in Data Cleaning:

  • Identifying Duplicates: Identifying duplicates is crucial to ensure that your analysis isn’t skewed by redundant data. Dataflows Gen 2, within the Power Query experience, offers robust built-in functions to detect and eliminate duplicate records. Additionally, in the SQL endpoint, you can utilize T-SQL's GROUP BY and HAVING clauses to efficiently identify duplicate entries . In the Spark Notebook environment, I first identified duplicates using the groupBy method and then removed them by applying the dropDuplicates method. These combined approaches provide a comprehensive strategy for maintaining data integrity across different tools in Microsoft Fabric.
  • Handling Missing Data: Missing data can be a significant challenge, particularly in large datasets where even small gaps can lead to biased results. Within Microsoft Fabric, PySpark’s flexibility allowed me to implement conditional logic for replacing null values with meaningful defaults or calculated values, depending on the specific context. For instance, in a sales dataset, I addressed missing revenue figures by calculating and substituting the average revenue for similar entries. To identify these null values, I used the WHERE clause on the revenue column. Power Query also offers a user-friendly interface to either remove or fill in missing values, depending on the specific use case, making it a versatile tool for data cleaning.
  • Converting Data Types: Ensuring consistent data types across your dataset is crucial for seamless data processing and analysis. In my project, I used PySpark to convert columns into appropriate data types — such as transforming text-based date columns into proper date formats or ensuring numerical data was correctly cast as integers or floats. In the SQL endpoint, this can be similarly achieved using the CAST function in T-SQL. These transformations are essential for maintaining data consistency and ensuring that subsequent analyses are both accurate and efficient.

The combination of Dataflows and PySpark provided a powerful and flexible environment for cleaning data, making sure that it was ready for the next stage of transformation.

Step 2: Data Enrichment — Adding Context to Your Data

After cleaning, the next step is to enrich your data by adding more context. This can involve adding new columns, creating calculated fields, or joining data from multiple sources to create a more comprehensive dataset.

Tools and Techniques for Data Enrichment:

  • Power Query: Power Query’s interface makes it easy to manipulate data. I used it to merge sales data from different regions, creating a unified dataset that included additional calculated columns like “Total Revenue” and “Revenue Per Product.”
  • Joining Data: In many cases, you’ll need to combine data from different tables or sources. For example, I joined customer demographic data with sales data to create a more detailed profile of customer behavior. This was easily achieved using the merge functionality in Power Query and the SQL endpoints in Fabric.
  • Creating New Columns: Sometimes, you need to derive new insights by creating calculated columns. While working on the project, I added a “Customer Lifetime Value” column by calculating the total revenue generated by each customer over time. This new metric was essential for segmenting customers and identifying high-value segments.

By the end of this stage, my dataset was not only clean but also enriched with additional context, making it more useful for analysis.

Step 3: Data Modeling — Structuring Data for Analysis

With clean and enriched data, I moved on to data modeling. This is where you structure your data in a way that makes it easy to query and analyze. Microsoft Fabric’s Lakehouse architecture is perfect for this, as it supports both structured and unstructured data, allowing for flexibility in how you organize your data.

Implementing a Star Schema:

  • Fact and Dimension Tables: I structured the data using a star schema, which involves creating a central fact table that stores transactional data, surrounded by dimension tables that store descriptive attributes. For example, in a sales dataset, the fact table might include columns like “Transaction ID,” “Date,” and “Amount,” while the dimension tables would include details like “Product Information,” “Customer Details,” and “Store Locations.”
  • Slowly Changing Dimensions (SCDs): Handling historical data changes is essential for accurate trend analysis and reporting in many business scenarios. Microsoft Fabric offers flexibility in implementing Slowly Changing Dimensions (SCDs), whether you need to overwrite data with Type 1 SCDs or track historical changes with Type 2 SCDs.

Type 2 SCDs are particularly useful when you need to maintain a historical record of changes, such as tracking updates to customer details over time. In my project, I used Type 2 SCDs to ensure that every change in customer data was recorded, enabling a detailed analysis of customer behavior and trends over time.

When working within a Lakehouse or Spark Notebook environment, you can take advantage of Delta Lake’s built-in versioning. Delta logs automatically store the history of all writes to a table, which may be sufficient for many use cases. This allows you to query historical data and revert to previous versions as needed. However, if you require more control over how changes are recorded, you can use the MERGE INTO operation from the Spark SQL library to update Delta tables manually. This operation enables precise control over how new data is merged with existing records, allowing for effective management of Type 2 SCDs.

For scenarios involving a Data Warehouse and the T-SQL experience, the process is slightly different due to the current lack of support for the MERGE operation in Fabric’s Data Warehouse. Instead, I loaded the incoming data into a staging table and then used a stored procedure to manage updates and inserts. This procedure involved checking for changes, and calculating the ValidFrom and ValidTo dates for each record, ensuring accurate tracking of historical changes.

A useful technique in this environment is row hashing, which can simplify the detection of changes in data. By creating a hash of each row’s values, you can quickly compare the hash values of the existing dataset against the new incoming data. If the hashes match, the record remains unchanged. If the hashes differ, you can identify the specific rows that need updating and then apply the necessary changes to the delta tables.

Within Microsoft Fabric you can effectively manage historical data changes, regardless of the specific environment or use case. By implementing SCDs, you can maintain an accurate historical record, enabling deeper insights into trends and changes over time.

Using Bridge Tables:

Say a company has many projects running, and employees are assigned to one or many projects. In a data model, this would mean that a many-to-many relationship exists between Dim_Projects and Dim_Employee. By setting up bridge tables which act as intermediaries between fact and dimension tables, the integrity of the data model is maintained while enabling complex queries. In the SQL View, you can use the CROSS APPLY function in combination with STRING_SPLIT to create bridge tables. The CROSS APPLY function allows you to split the data and join it with other tables dynamically, while STRING_SPLIT helps in breaking down comma-separated values into rows, making it easier to map employees to their respective projects. This approach is particularly useful when you need to break down complex many-to-many relationships into manageable one-to-many mappings.

Conclusion

My experience with Microsoft Fabric was transformative — literally. The platform’s comprehensive toolset made it possible to manage every aspect of the data processing pipeline, from initial cleaning to complex modeling. For anyone looking to get serious about data transformation, Microsoft Fabric offers an accessible yet powerful solution that can handle even the most demanding tasks.

Whether you’re just starting out or looking to enhance your data transformation capabilities, I highly recommend diving into Microsoft Fabric. It’s a platform that enables you to turn raw data into actionable insights, all within a single, integrated environment.

--

--

Linda Olela

A dedicated software developer with a passion for solving real-world problems through technology. CEO & Founder of KenyaAbroad