Power BI & Tableau Resources
55.7K subscribers
391 photos
18 files
596 links
๐Ÿ†“ Resources to learn Power BI, Tableau & Data Visualisation

Perfect channel to start learning everything about Data Analytics

Admin: @coderfun
Download Telegram
Which of the following is NOT typically an operation performed by Group By?
Anonymous Quiz
8%
A) Sum
8%
B) Average
4%
C) Count
80%
D) Create a line chart
You have Quantity and Price columns and want to create a new Sales Amount column using Quantity ร— Price. Which Power Query feature is most appropriate?
Anonymous Quiz
14%
A) Group By
50%
B) Custom Column
30%
C) Conditional Column
7%
D) Remove Duplicates
โค2
๐Ÿš€ ๐—ช๐—ต๐—ถ๐—ฐ๐—ต ๐—ง๐—ฒ๐—ฐ๐—ต ๐—ฆ๐—ธ๐—ถ๐—น๐—น ๐—ช๐—ถ๐—น๐—น ๐—ฌ๐—ผ๐˜‚ ๐— ๐—ฎ๐˜€๐˜๐—ฒ๐—ฟ ๐—ถ๐—ป ๐Ÿฎ๐Ÿฌ๐Ÿฎ๐Ÿฒ?

Want to build apps, uncover insights, or create AI solutions? Explore certification courses that match your career goals! ๐ŸŽฏ

๐Ÿ’ป ๐—™๐˜‚๐—น๐—น ๐—ฆ๐˜๐—ฎ๐—ฐ๐—ธ ๐——๐—ฒ๐˜ƒ๐—ฒ๐—น๐—ผ๐—ฝ๐—บ๐—ฒ๐—ป๐˜
๐Ÿ‘‰ https://pdlink.in/3SuUeuD

๐Ÿ“Š ๐——๐—ฎ๐˜๐—ฎ ๐—”๐—ป๐—ฎ๐—น๐˜†๐˜๐—ถ๐—ฐ๐˜€
๐Ÿ‘‰ https://pdlink.in/45vk5ph

๐Ÿ’ซ๐—”๐—œ ๐—˜๐—ป๐—ด๐—ถ๐—ป๐—ฒ๐—ฒ๐—ฟ๐—ถ๐—ป๐—ด
๐Ÿ‘‰ https://pdlink.in/4fWJVID

๐Ÿ”ฅ Choose your path, sharpen your skills, and take the next step towards your tech career!

๐Ÿ“Œ Save this post & share it with a friend planning to upskill.
โค1
๐Ÿ“Š Power BI Learning Roadmap โ€” Part 4

Topic 9: Pivot, Unpivot & Transpose in Power Query

These three transformations are extremely useful when your source data is arranged in a way that isn't ideal for analysis.

A common Power BI problem isn't that the data is incorrect โ€” it's that the structure of the data is not suitable for a data model.

1. Pivot Columns

Pivoting converts values from rows into separate columns.

Suppose your data looks like this:

Region | Month | Sales

West | Jan | 50,000

West | Feb | 60,000

South | Jan | 40,000

South | Feb | 45,000

You could pivot the Month column to create:

Region | Jan | Feb

West | 50,000 | 60,000

South | 40,000 | 45,000

Now the values from the Month column have become separate columns.

When is Pivot useful?

Pivot can be useful when the business specifically requires a wide format.

For example: Region | Jan | Feb | Mar | Apr might be useful for a particular reporting output.

However, a wide structure isn't always the best structure for a Power BI data model.

2. Unpivot Columns

Unpivot does the opposite. It converts multiple columns into rows.

Suppose your source looks like this:

Region | Jan | Feb | Mar

West | 50,000 | 60,000 | 55,000

South | 40,000 | 45,000 | 48,000

You can unpivot the month columns to create:

Region | Month | Sales

West | Jan | 50,000

West | Feb | 60,000

West | Mar | 55,000

South | Jan | 40,000

South | Feb | 45,000

South | Mar | 48,000

Now Month is a column containing values rather than separate columns.

3. Why Unpivot Is So Important

Imagine a company provides a monthly report like this:

Employee | Jan | Feb | Mar | Apr | May

Rahul | 20 | 22 | 18 | 25 | 21

Priya | 18 | 20 | 24 | 23 | 26

Next month, they add: Jun

The source structure keeps changing because every month becomes another column.

After unpivoting, the structure becomes:

Employee | Month | Hours

Rahul | Jan | 20

Rahul | Feb | 22

Rahul | Mar | 18

Priya | Jan | 18

Priya | Feb | 20

Priya | Mar | 24

When June arrives, June simply becomes another value in the Month column.

4. Unpivot Other Columns

Suppose your table contains:

Employee | Department | Jan | Feb | Mar

Rahul | Finance | 20 | 22 | 18

Priya | HR | 18 | 20 | 24

You want to preserve Employee and Department and convert the remaining columns into rows.

Unpivot Other Columns is particularly useful here. You select the columns you want to keep, and Power Query unpivots the remaining columns.

5. Attribute and Value Columns

After unpivoting, Power Query generally creates two important columns.

Attribute: Contains the names of the columns that were unpivoted.

Example: Jan, Feb, Mar

Value: Contains the corresponding values. Example: 20, 22, 18

You can rename these to something more meaningful.

For example: Attribute โ†’ Month, Value โ†’ Hours.

6. Transpose

Transpose is different from Pivot and Unpivot. Transpose essentially turns rows into columns and columns into rows.

Suppose your data is:

Name | Rahul | Priya | Amit

Sales | 80,000 | 70,000 | 60,000

Region | West | South | North

After transposing, the orientation changes.
โค2
Transpose changes the physical orientation of the table.

7. Pivot vs Unpivot vs Transpose

Pivot: Turns values into columns. Rows โ†’ Columns

Unpivot: Turns columns into rows. Columns โ†’ Rows

Transpose: Flips the orientation of the entire table. Rows โ†” Columns

๐ŸŽฏ Real-World Example

Imagine an organization sends you this monthly sales report:

Region | Jan | Feb | Mar | Apr

West | 80 | 90 | 95 | 100

South | 60 | 65 | 70 | 75

North | 50 | 55 | 58 | 62

You could unpivot the month columns:

Region | Month | Sales

West | Jan | 80

West | Feb | 90

West | Mar | 95

West | Apr | 100

South | Jan | 60

South | Feb | 65

Now you can easily analyze: Monthly trends, Regional performance, Month-over-month changes, Yearly comparisons.

โš ๏ธ Common Mistake

Don't assume that every dataset should be unpivoted. The correct transformation depends on: What the data represents, How the source is structured, How the data will be analyzed, Whether the columns represent actual attributes or repeated categories.

๐ŸŽฏ Practical Exercise

Take a dataset structured like:

Product | Jan | Feb | Mar | Apr

Laptop | 100 | 120 | 140 | 150

Monitor | 80 | 90 | 110 | 125

Keyboard | 50 | 60 | 70 | 75

Try the following in Power Query:

1. Unpivot the month columns.

2. Rename Attribute to Month.

3. Rename Value to Sales.

4. Observe the resulting structure.

5. Try pivoting the data back.

6. Create a small table and experiment with Transpose.

๐Ÿ’ก Key takeaway: Pivot, Unpivot, and Transpose aren't just buttons to memorize. They are tools for changing the structure of your data so that it better matches the way you need to analyze it.

Double Tap โค๏ธ For More
โค5
๐—ง๐—ข๐—ฃ ๐—™๐—ฅ๐—˜๐—˜ ๐—–๐—ข๐—จ๐—ฅ๐—ฆ๐—˜๐—ฆ ๐—ง๐—ข ๐—•๐—ข๐—ข๐—ฆ๐—ง ๐—ฌ๐—ข๐—จ๐—ฅ ๐—ฆ๐—ž๐—œ๐—Ÿ๐—Ÿ๐—ฆ ๐—œ๐—ก ๐Ÿฎ๐Ÿฌ๐Ÿฎ๐Ÿฒ!

Explore FREE online learning resources to develop in-demand skills and improve your career opportunities!

๐ŸŽ“ Why Explore These Courses?
โœ… Learn valuable professional skills
โœ… Improve your resume
โœ… Build practical knowledge
โœ… Learn at your own pace

๐—˜๐˜…๐—ฝ๐—น๐—ผ๐—ฟ๐—ฒ ๐—™๐—ฅ๐—˜๐—˜ ๐—–๐—ผ๐˜‚๐—ฟ๐˜€๐—ฒ๐˜€ ๐—›๐—ฒ๐—ฟ๐—ฒ๐Ÿ‘‡

https://pdlink.in/3VBdt6V

๐Ÿ’ก Learn New Skills โ†’ Build Confidence โ†’ Unlock Career Opportunities!
โค2
๐Ÿ“Š Power BI Learning Roadmap โ€” Part 4

Topic 10: Merge Queries and Append Queries in Power Query

When working with real-world data, you rarely get everything in one table.

You may have:

โ€ข Sales data in one table

โ€ข Product information in another

โ€ข Customer information in another

โ€ข Monthly sales in separate files

Power Query provides two important features to combine these datasets:

1. Merge Queries

2. Append Queries

The key difference is simple:

โ€ข Merge Queries = add columns from another table

โ€ข Append Queries = add rows from another table

1. Merge Queries

Merge Queries is used when you want to combine two tables based on a common column.

It is similar to a JOIN in SQL or a lookup such as XLOOKUP in Excel.

Example

Sales table:

ProductID Quantity Sales

P101 10 5000

P102 5 3000

P103 8 6400

Products table:

ProductID ProductName Category

P101 Laptop Electronics

P102 Mouse Accessories

P103 Keyboard Accessories

Both tables contain ProductID. We can merge them using ProductID.

After merging and expanding:

ProductID Quantity Sales ProductName Category

P101 10 5000 Laptop Electronics

P102 5 3000 Mouse Accessories

P103 8 6400 Keyboard Accessories

2. How to Merge Queries

In Power Query:

1. Select the first table.

2. Go to Home.

3. Select Merge Queries.

4. Select the second table.

5. Select the matching column in both tables.

6. Choose the Join Kind.

7. Click OK.

8. A new column containing a table will appear.

9. Click the Expand button.

10. Select the columns you want to bring into the first table.

3. Join Keys

The column used to match two tables is called a key.

For example:

ProductID

Both tables should have compatible data types. If one table has ProductID = Text and the other has ProductID = Number, the merge may not work as expected.

Always check the data type before merging.

4. Types of Joins

Left Outer

Keeps every row from the first table and brings matching rows from the second table. This is one of the most commonly used joins.

Inner

Keeps only rows that have a match in both tables.

Right Outer

Keeps all rows from the second table and matching rows from the first table.

Full Outer

Keeps all rows from both tables. Matching rows are combined, while unmatched rows are also retained.

Left Anti

Returns rows from the first table that do NOT have a match in the second table. This is extremely useful for finding missing records.

Example: If Sales has P101, P102, P103, P104 and Products has P101, P102, P103, Left Anti identifies P104.

Right Anti

The opposite of Left Anti. It identifies records that exist in the second table but not in the first.

5. A Very Important Problem: Duplicate Keys

Suppose your Products table contains:

P101 Laptop

P101 Laptop - New

And your Sales table contains P101 5000

If you merge these tables, Power Query may produce multiple rows for P101. This can unintentionally increase your row count. So before merging, understand whether your key is unique.

6. Append Queries

Append is completely different from Merge. Append combines tables by stacking rows.

Example:

January Sales: Laptop 5000, Mouse 2000

February Sales: Laptop 6000, Mouse 2500

After Append: All rows stacked vertically.

7. Append Two Queries
โค1
If you have two tables: January Sales and February Sales

Use: Home โ†’ Append Queries โ†’ Append Queries as New

Then select the two queries.

8. Append Three or More Queries

You can also append more than two tables, for example January to June. All can be combined into one Sales table. This is useful when monthly data is stored separately.

9. What If Column Names Are Different?

Suppose January contains Product Sales and February contains Product Revenue. Power Query treats Sales and Revenue as different columns, resulting in null values. So before appending, make sure equivalent columns have consistent names.

10. Merge vs Append

Merge

You have Sales (ProductID | Sales) and Products (ProductID | ProductName | Category). You want ProductID | Sales | ProductName | Category. You are adding columns. Use Merge.

Append

You have January Sales (Product | Sales) and February Sales (Product | Sales). You want one larger table containing all records. You are adding rows. Use Append.

11. Real-World Example

Imagine you work for a bank. You receive transaction files every month: Jan_Transactions.csv, Feb_Transactions.csv, Mar_Transactions.csv.

Each file contains Transaction ID, Account ID, Date, Amount, Currency. You can append all three files into one transaction table.

Then you have a separate Account Master table with Account ID, Customer Name, Region, Account Type.

You can merge the Account Master into the transaction table using Account ID.

12. Common Mistakes

Mistake 1: Choosing the wrong key

Using Customer Name instead of Customer ID can create unreliable matches. Prefer stable identifiers such as CustomerID, AccountID, ProductID.

Mistake 2: Different data types

Text and Number columns cannot reliably match. Check the data type before merging.

Mistake 3: Duplicate keys

Duplicate keys in the lookup table can multiply rows. Always investigate unexpected row-count increases.

Mistake 4: Wrong Join Kind

Choosing Inner instead of Left Outer can cause unmatched records to disappear.

Mistake 5: Appending inconsistent columns

If one file calls a column Sales and another calls it Revenue, Power Query treats them as separate columns. Standardize column names before appending.

๐Ÿงช Practical Exercise

Create these three tables.

Sales: P101 5000, P102 3000, P103 7000

Products: P101 Laptop Electronics, P102 Mouse Accessories, P103 Keyboard Accessories

January: P101 5000, P102 3000

February: P101 6000, P102 3500

Try to:

1. Merge Sales with Products.

2. Bring ProductName and Category into Sales.

3. Append January and February.

4. Check the final row count.

5. Try a Left Anti join and identify products missing.

๐ŸŽฏ Double Tap โค๏ธ For More
โค7
๐——๐—ฎ๐˜๐—ฎ ๐˜€๐—ฐ๐—ถ๐—ฒ๐—ป๐—ฐ๐—ฒ ๐—–๐—ฒ๐—ฟ๐˜๐—ถ๐—ณ๐—ถ๐—ฐ๐—ฎ๐˜๐—ถ๐—ผ๐—ป ๐—ช๐—ถ๐˜๐—ต ๐—”๐—œ๐Ÿ˜

Future Ready Data Science and AI Skills You Build

->Build Python, Machine Learning, and AI Skills
->Get Mentored by Industry Experts
->Practice with Mock Interviews
->Ace Your Placements & Land Dream Tech Job

๐Ÿค 500+ Partner Companies |๐ŸŽ“ 2000+ Students Placed

๐Ÿ”— ๐—ฅ๐—ฒ๐—ด๐—ถ๐˜€๐˜๐—ฒ๐—ฟ ๐—ก๐—ผ๐˜„ ๐Ÿ‘‡ :-

https://pdlink.in/47pezFz

๐Ÿ“ฒ Save & Share with Friends Preparing for Data Science & AI Jobs!
๐—œ๐—•๐—  ๐—™๐—ฅ๐—˜๐—˜ ๐—ง๐—˜๐—–๐—› ๐—–๐—ข๐—จ๐—ฅ๐—ฆ๐—˜๐—ฆ ๐Ÿฎ๐Ÿฌ๐Ÿฎ๐Ÿฒ! ๐ŸŽ“

Explore IBM Cognitive Class and build in-demand tech skills without spending money on course fees!

๐Ÿ“š ๐—ง๐—ผ๐—ฝ ๐—™๐—ฅ๐—˜๐—˜ ๐—–๐—ผ๐˜‚๐—ฟ๐˜€๐—ฒ๐˜€ ๐˜๐—ผ ๐—˜๐˜…๐—ฝ๐—น๐—ผ๐—ฟ๐—ฒ:-

๐Ÿ’ซ Artificial Intelligence & Machine Learning
๐Ÿ”ฅPython for Data Science
๐Ÿ“Š Data Science Fundamentals
โ˜๏ธ Cloud Computing & Big Data

๐Ÿ”— ๐—ฆ๐˜๐—ฎ๐—ฟ๐˜ ๐—Ÿ๐—ฒ๐—ฎ๐—ฟ๐—ป๐—ถ๐—ป๐—ด ๐—›๐—ฒ๐—ฟ๐—ฒ ๐Ÿ‘‡

https://pdlink.in/4zGswuX

๐Ÿ“ฒ Save & Share with friends preparing for tech careers! ๐Ÿ”ฅ
๐Ÿ“Š Power BI Learning Roadmap โ€” Part 4

Topic 12: Power Query M Language

Until now, we have mostly used the Power Query interface to clean and transform data.

But behind almost every transformation you perform in Power Query, there is code.

That language is called M.

Understanding M doesn't mean you need to become a programmer. You just need to understand how Power Query represents the transformations you perform.

1. What is M Language?

M is the language used by Power Query for data transformation.

For example, when you:

โ€ข Remove columns

โ€ข Filter rows

โ€ข Change data types

โ€ข Rename columns

โ€ข Add custom columns

โ€ข Merge queries

โ€ข Append queries

โ€ข Group data

Power Query creates M code for those actions.

You can see this code in:

View โ†’ Advanced Editor

2. A Simple M Example

Suppose your table contains:

Product Sales

Laptop 10000

Mouse 3000

Keyboard 5000

If you filter Sales greater than 4000, Power Query generates an M expression similar to:

Table.SelectRows(Source, each [Sales] > 4000)


This means:

Take the Source table and keep rows where Sales is greater than 4000.

You don't have to memorize this immediately.

The goal is to understand what the code is doing.

3. Power Query Steps Are M Code

When you perform transformations, Power Query creates individual steps.

For example:

Source

Changed Type

Removed Columns

Filtered Rows

Renamed Columns

Each step represents a transformation.

The formula bar can show the M expression behind the selected step.

This is one of the easiest ways to learn M.

Instead of starting with programming syntax, perform a transformation and observe the code Power Query generates.

4. The let and in Structure

A typical Power Query query looks like:

let
Source = Excel.Workbook(File.Contents("Sales.xlsx")),
SalesData = Source{[Item="Sales"]}[Data],
ChangedType = Table.TransformColumnTypes(
SalesData,
{{"Sales", type number}}
)
in
ChangedType


Don't worry about every part yet.

The important idea is:

let
Step 1,
Step 2,
Step 3
in
Final Step


Power Query performs the steps in sequence and returns the step specified after in.

5. Understanding a Step

Consider:

FilteredRows =
Table.SelectRows(Source, each [Sales] > 5000)


There are two important parts.

Step name

FilteredRows

This is the name of the step.

Transformation

Table.SelectRows(Source, each [Sales] > 5000)

This tells Power Query what transformation to perform.

6. Common M Functions

You will frequently encounter functions such as:

Table.SelectRows

Used to filter rows.

Table.SelectRows(Source, each [Sales] > 5000)


Table.RemoveColumns

Used to remove columns.

Table.RemoveColumns(Source, {"Region"})


Table.RenameColumns

Used to rename columns.

Table.RenameColumns(Source, {{"Sales", "Revenue"}})


Table.AddColumn

Used to create a new column.

Table.AddColumn(Source, "Profit", each [Sales] - [Cost])
These functions become much easier to understand once you recognize the pattern.

7. The each Keyword

You will see each frequently in Power Query.

For example:

each [Sales] > 5000

It means the expression should be evaluated for each row.

Another example:

each [Quantity] * [Price]

This calculates the result for every row.

If:

Quantity = 10

Price = 500

then:

10 ร— 500 = 5000

8. Column References

In M, a column can commonly be referenced like:

[Sales]

For example:

each [Sales] * 1.18

This calculates a value using the Sales column.

For column names containing spaces or special characters, you may see syntax such as:

[#"Sales Amount"]

You don't need to memorize this immediately. Power Query usually generates the correct syntax for you.

9. M Is Case-Sensitive

M language is case-sensitive.

For example:

Sales

and

sales

are not necessarily treated as the same identifier.

Similarly, function names need to be written correctly.

This is one reason copying and modifying existing M code is often easier than writing everything from scratch.

10. Editing M Code

You can modify M code directly using:

View โ†’ Advanced Editor

For example, you might change:

[Sales] > 5000

to:

[Sales] > 10000

This changes the filtering condition.

However, don't edit M code blindly.

If you change a step incorrectly, later steps may stop working.

11. Why Learn M If Power Query Has a GUI?

The interface is enough for many common transformations.

But M becomes useful when:

โ€ข A transformation isn't easily available through the interface

โ€ข You need dynamic logic

โ€ข You want to reuse code

โ€ข You need parameters

โ€ข You want to create custom functions

โ€ข You need more control over transformations

โ€ข You want to troubleshoot query errors

Think of the GUI as the easy way to build transformations.

M gives you deeper control over those transformations.

12. M vs DAX

This is an important distinction.

Power Query M

Used mainly for:

โ€ข Extracting data

โ€ข Cleaning data

โ€ข Transforming data

โ€ข Combining data

โ€ข Preparing data before loading

DAX

Used mainly for:

โ€ข Measures

โ€ข Calculated columns

โ€ข Calculations within the data model

โ€ข Analysis and reporting

For example:

Removing unnecessary columns:

Use Power Query.

Creating:

Total Sales = SUM(Sales[SalesAmount])

Use DAX.

๐Ÿงช Practical Exercise

Take a simple Sales table containing:

Product Quantity Price

Laptop 2 50000

Mouse 5 1000

Keyboard 3 2000

In Power Query:

1. Change the data types.

2. Add a Revenue column.

3. Filter Revenue greater than 5000.

4. Rename the Revenue column.

5. Open the formula bar.

6. Look at the M code generated for each step.

7. Open Advanced Editor.

8. Identify the let and in sections.

๐ŸŽฏ Key Takeaway

M is the language behind Power Query transformations.

You don't need to learn all of M at once.

Start by performing transformations through the interface, then study the M code Power Query generates.

This approach makes M much easier to learn because you already understand what the code is supposed to accomplish.

Double Tap โค๏ธ For More
โค4
๐Ÿฐ ๐—™๐—ฅ๐—˜๐—˜ ๐—–๐—ผ๐˜‚๐—ฟ๐˜€๐—ฒ๐˜€ ๐—ง๐—ผ ๐— ๐—ฎ๐˜€๐˜๐—ฒ๐—ฟ ๐—–๐—ผ๐—ฑ๐—ถ๐—ป๐—ด ๐—™๐—ผ๐—ฟ ๐—™๐—ฅ๐—˜๐—˜๐Ÿ˜

โœ… 100% FREE YouTube Learning
โœ… Beginner-Friendly Programming Tutorials
โœ… Learn Popular & In-Demand Tech Skills
โœ… Study at Your Own Pace
โœ… Build a Strong Foundation for Coding Interviews

๐Ÿ”— ๐—”๐—ฐ๐—ฐ๐—ฒ๐˜€๐˜€ ๐—”๐—Ÿ๐—Ÿ ๐Ÿฐ ๐—™๐—ฅ๐—˜๐—˜ ๐—–๐—ผ๐˜‚๐—ฟ๐˜€๐—ฒ๐˜€ ๐Ÿ‘‡:-

https://pdlink.in/3WcuMvi

โšก Your coding journey can start todayโ€”completely FREE!
๐—ง๐—”๐—ง๐—” ๐—™๐—ฅ๐—˜๐—˜ ๐— ๐—œ๐—–๐—ฅ๐—ข-๐—œ๐—ก๐—ง๐—˜๐—ฅ๐—ก๐—ฆ๐—›๐—œ๐—ฃ๐—ฆ ๐Ÿฎ๐Ÿฌ๐Ÿฎ๐Ÿฒ! ๐ŸŽ“

โœ… 100% FREE Learning Experience
โœ… Short Programs โ€” Approximately 4โ€“6 Hours
โœ… Practical, Real-World Tasks
โœ… Self-Paced & Online
โœ… Certificate Opportunities for Your Resume & LinkedIn
โœ… No Traditional Interview Process

๐Ÿ”— ๐—˜๐˜…๐—ฝ๐—น๐—ผ๐—ฟ๐—ฒ ๐—ง๐—”๐—ง๐—” ๐—™๐—ฅ๐—˜๐—˜ ๐— ๐—ถ๐—ฐ๐—ฟ๐—ผ-๐—œ๐—ป๐˜๐—ฒ๐—ฟ๐—ป๐˜€๐—ต๐—ถ๐—ฝ๐˜€๐Ÿ‘‡:-

https://pdlink.in/4yWgaPn

โšก Don't wait for your first job to start gaining practical experience!
๐Ÿ“Š Power BI Learning Roadmap โ€” Part 4

Topic 13: Custom M Functions

After learning the basics of M language, the next important concept is Custom Functions.

Custom functions allow you to write a transformation once and reuse it multiple times.

This becomes very useful when you have many files or tables that need the same transformation logic.

1. What Is a Custom Function?

A custom function is a reusable piece of M code that accepts an input and returns an output.

For example, suppose you frequently need to calculate:

Price + 18% GST

Instead of writing the calculation separately for every query, you can create a function.

Conceptually:

Input: Price

Function: Price ร— 1.18

Output: Price including GST

If the input is โ‚น1,000:

1000 ร— 1.18 = 1180

2. Why Use Custom Functions?

Imagine you receive 12 monthly files.

Every file requires the same transformations:

โ€ข Remove unnecessary columns

โ€ข Change data types

โ€ข Clean product names

โ€ข Calculate revenue

โ€ข Standardize dates

You could repeat the same steps manually.

But with a custom function, you can define the transformation once and apply it to each input.

This saves time and makes your Power Query solution easier to maintain.

3. Basic Function Structure

A simple M function can look like:

(price as number) as number =>
price * 1.18


Here:

price is the input.

as number specifies the input data type.

price * 1.18 is the calculation.

The final as number specifies the output type.

4. Using the Function

Suppose your function is called:

AddGST

You could use it like:

AddGST(1000)

Result:

1180

Another example:

AddGST(5000)

Result:

5900

The same logic can be reused with different values.

5. Functions Can Accept Multiple Inputs

A function doesn't have to accept only one parameter.

For example:

(price as number, taxRate as number) as number =>
price * (1 + taxRate)
Now you can provide both the price and tax rate.

For example:

CalculatePrice(1000, 0.18)

Result:

1180

And:

CalculatePrice(1000, 0.05)

Result:

1050

The function becomes more flexible.

6. Custom Functions with Tables

Custom functions become especially powerful when working with tables.

Imagine you receive these files:

January.xlsx

February.xlsx

March.xlsx

April.xlsx

Each file contains raw sales data.

You want every file to go through the same cleaning process.

You can create a function such as:

TransformSalesFile

The function can:

1. Receive a file.

2. Extract the required table.

3. Remove unnecessary columns.

4. Rename columns.

5. Change data types.

6. Clean the data.

7. Return the transformed table.

You can then apply the function to multiple files.

7. Custom Function Workflow

A common workflow is:

Files โ†’ Function โ†’ Cleaned Tables โ†’ Combined Dataset

For example:

Jan.xlsx

Feb.xlsx

Mar.xlsx

Each file is passed through the same transformation function.

The result is a consistent dataset ready for analysis.

This is one of the most useful applications of custom functions in Power Query.

8. Creating a Function from an Existing Query

Power Query can also help you create a function from an existing query.

A common approach is:

1. Build the transformation for one sample file.

2. Turn the query into a function.

3. Define the input parameter.

4. Apply the function to other files.

This is much easier than manually writing the entire function from scratch.

9. Function vs Parameter

These two concepts can sometimes be confused.

Parameter

A parameter stores a value that can change.

Example:

MinimumSales = 5000

Function

A function performs an operation using one or more inputs.

Example:

CalculateProfit(Sales, Cost)

So:

Parameter = value

Function = reusable logic

10. Real-World Example

Suppose your company receives employee files from different branches.

Each file contains:

Name Salary Department

Rahul 50000 Sales

Priya 60000 HR

Every file needs the same cleaning:

โ€ข Remove blank rows

โ€ข Standardize department names

โ€ข Change Salary to number

โ€ข Trim employee names

Instead of repeating these steps for every branch, create:

CleanEmployeeFile

Then apply that function to every branch file.

If you later modify the cleaning logic, you can update the function rather than rebuilding the transformation for every file.

11. Important: Functions Need Consistent Inputs

A custom function works best when the input structure is predictable.

For example, if your function expects:

โ€ข Name

โ€ข Salary

โ€ข Department

but one file contains:

โ€ข EmployeeName

โ€ข Pay

โ€ข Team

the function may fail.

Therefore, when working with multiple files, make sure the files have a consistent structure or build logic to handle differences.

12. Common Mistakes

Mistake 1: Creating a function for everything

Not every transformation needs a custom function.

Use functions when the same logic needs to be reused.

Mistake 2: Wrong input data type

If your function expects a number but receives text, the function may produce an error.

Mistake 3: Inconsistent file structures

Different column names or missing columns can break a function.
โค2
Mistake 4: Not testing the function

Always test your function with a few inputs before applying it to hundreds of files.

๐Ÿงช Practical Exercise

Create a simple function that calculates profit margin.

Use:

โ€ข Sales

โ€ข Cost

Formula:

(Sales - Cost) / Sales

For example:

Sales = โ‚น10,000

Cost = โ‚น7,000

Profit Margin:

(10000 - 7000) / 10000

= 0.30

= 30%

Then test your function with different Sales and Cost values.

After that, think about how you could use the same concept to transform multiple monthly files.

๐ŸŽฏ Key Takeaway

Custom M Functions allow you to write transformation logic once and reuse it many times.

They are particularly valuable when working with multiple files that require the same cleaning and transformation steps.

Double Tap โค๏ธ For More
โค5
๐— ๐—œ๐—–๐—ฅ๐—ข๐—ฆ๐—ข๐—™๐—ง ๐—™๐—ฅ๐—˜๐—˜ ๐——๐—”๐—ง๐—” ๐—ฆ๐—–๐—œ๐—˜๐—ก๐—–๐—˜ ๐—ฅ๐—˜๐—ฆ๐—ข๐—จ๐—ฅ๐—–๐—˜๐—ฆ ๐Ÿฎ๐Ÿฌ๐Ÿฎ๐Ÿฒ! ๐ŸŽ“

Microsoft offers valuable FREE learning resources to help you develop in-demand technical skills! ๐Ÿ’ป

โœ… 100% FREE Learning Resources
โœ… Beginner-Friendly Tutorials
โœ… Self-Paced Learning
โœ… Practical Skills for Real-World Projects
โœ… Useful for Data Analytics & Data Science Career Preparation

๐Ÿ”— ๐—”๐—ฐ๐—ฐ๐—ฒ๐˜€๐˜€ ๐—”๐—Ÿ๐—Ÿ ๐Ÿฐ ๐—™๐—ฅ๐—˜๐—˜ ๐—ฅ๐—ฒ๐˜€๐—ผ๐˜‚๐—ฟ๐—ฐ๐—ฒ๐˜€ ๐Ÿ‘‡:-

https://pdlink.in/4k6ylNq

โšก Your Data Science journey can start today โ€” completely FREE!
โค1
๐——๐—ฎ๐˜๐—ฎ ๐—ฆ๐—ฐ๐—ถ๐—ฒ๐—ป๐—ฐ๐—ฒ & ๐— ๐—ฎ๐—ฐ๐—ต๐—ถ๐—ป๐—ฒ ๐—Ÿ๐—ฒ๐—ฎ๐—ฟ๐—ป๐—ถ๐—ป๐—ด ๐—™๐—ฅ๐—˜๐—˜ ๐—ข๐—ป๐—น๐—ถ๐—ป๐—ฒ ๐— ๐—ฎ๐˜€๐˜๐—ฒ๐—ฟ๐—ฐ๐—น๐—ฎ๐˜€๐˜€ ๐Ÿ“Š

Build a strong foundation in Data Science .Explore Machine Learning and Deep Learning

Eligibility :- Students โ€ข Freshers โ€ข Working Professionals

๐Ÿ“… Date:- 23 October 2026
โฐ Time:- 7:00 PMโ€“9:00 PM IST
๐Ÿ’ป Mode:- Online

๐Ÿ”— ๐—ฅ๐—ฒ๐—ด๐—ถ๐˜€๐˜๐—ฒ๐—ฟ ๐—™๐—ผ๐—ฟ ๐—™๐—ฅ๐—˜๐—˜๐Ÿ‘‡ :-

https://pdlink.in/4i8MKGn

๐Ÿ“ข Share this opportunity with your friends and classmates.
โค3
๐Ÿš€๐— ๐—”๐—ฆ๐—ง๐—˜๐—ฅ ๐—˜๐—ซ๐—–๐—˜๐—Ÿ ๐—™๐—ข๐—ฅ ๐—™๐—ฅ๐—˜๐—˜ ๐—œ๐—ก ๐Ÿฎ๐Ÿฌ๐Ÿฎ๐Ÿฒ! ๐Ÿ“Š

Discover 4 FREE Websites to learn Microsoft Excel from beginner to advanced level! ๐ŸŽ“

๐Ÿ”ฅ FREE Learning Resources
๐Ÿ”ฅ Beginner to Advanced Tutorials
๐Ÿ”ฅ Practical Examples & Exercises
๐Ÿ”ฅ Learn Anytime, Anywhere

๐Ÿ”— ๐—Ÿ๐—ถ๐—ป๐—ธ๐Ÿ‘‡:-

https://pdlink.in/4jDfcCP

โšก One powerful skill can open doors to multiple career opportunities!
๐Ÿคฃ1