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

Compete to become Power BI Data Viz World Champion! First round ends August 18th. Get started.

Reply
Mackac2004
New Member

Joining three tabs in Excel and importing only required fields

Hi,

 

I have an Excel file with three tabs. I need to only import the required fields from them to Power BI. How do I create a script in M language and where do I add it in power bi? I am new to power bi and I tried using codes but I get errors.


keys:

The first two are linked by dates. And they are linked to the third by country codes.

 

Thank you.

2 ACCEPTED SOLUTIONS
rohit1991
Super User
Super User

Steps to Import and Link Excel Data in Power BI

  1. Load Data: Go to Home > Get Data > Excel Workbook, select your file, and click Transform Data to open the Power Query Editor.

  2. Filter Columns: Select only the required columns for each tab, right-click, and choose Remove Other Columns.

  3. Rename Queries: Rename queries to meaningful names (e.g., Tab1, Tab2, Tab3).

  4. Merge Queries: Use Home > Merge Queries to: Merge Tab1 and Tab2 using Date as the key. Merge with Tab3 using CountryCode as the key.

  5. Apply Changes: Click Close & Apply to load data into Power BI.

  6. Set Relationships: In Model View, ensure relationships: Tab1 ↔ Tab2 on Date. Tab1/Tab2 ↔ Tab3 on CountryCode.

Code :

let
Source = Excel.Workbook(File.Contents("C:\YourFilePath\YourFile.xlsx"), null, true),
Tab1_Sheet = Source{[Name="Tab1"]}[Content],
PromotedHeaders = Table.PromoteHeaders(Tab1_Sheet, [PromoteAllScalars=true]),
SelectedColumns = Table.SelectColumns(PromotedHeaders, {"Date", "CountryCode", "Sales"}),
FilteredRows = Table.SelectRows(SelectedColumns, each [Sales] > 0)
in
FilteredRows

 

 


Did it work? ✔ Give a Kudo • Mark as Solution – help others too!

View solution in original post

Anonymous
Not applicable

Hi @Mackac2004 

 

Selecting “Transform Data” when you import data will take you to the Power Query Editor screen, where you can use the M language. You can also click “Transform data” in the Home screen to enter the Power Query Editor screen at any time.

vxianjtanmsft_0-1733277804317.png

vxianjtanmsft_1-1733277836200.png

The Advanced Editor lets you see the code that Power Query Editor is creating with each step. It also lets you create your own code in the Power Query M formula language.

vxianjtanmsft_4-1733278866670.png

Please refer to Query overview in Power BI Desktop - Power BI | Microsoft Learn

 

Also you can consider using the append query and merge query functions to combine multiple tables.

Append queries - Power Query | Microsoft Learn

Merge queries overview - Power Query | Microsoft Learn

 

 

Best Regards,
Jarvis Tang
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

 

 

 

 

View solution in original post

3 REPLIES 3
Anonymous
Not applicable

Hi @Mackac2004 

 

Selecting “Transform Data” when you import data will take you to the Power Query Editor screen, where you can use the M language. You can also click “Transform data” in the Home screen to enter the Power Query Editor screen at any time.

vxianjtanmsft_0-1733277804317.png

vxianjtanmsft_1-1733277836200.png

The Advanced Editor lets you see the code that Power Query Editor is creating with each step. It also lets you create your own code in the Power Query M formula language.

vxianjtanmsft_4-1733278866670.png

Please refer to Query overview in Power BI Desktop - Power BI | Microsoft Learn

 

Also you can consider using the append query and merge query functions to combine multiple tables.

Append queries - Power Query | Microsoft Learn

Merge queries overview - Power Query | Microsoft Learn

 

 

Best Regards,
Jarvis Tang
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

 

 

 

 

rohit1991
Super User
Super User

Steps to Import and Link Excel Data in Power BI

  1. Load Data: Go to Home > Get Data > Excel Workbook, select your file, and click Transform Data to open the Power Query Editor.

  2. Filter Columns: Select only the required columns for each tab, right-click, and choose Remove Other Columns.

  3. Rename Queries: Rename queries to meaningful names (e.g., Tab1, Tab2, Tab3).

  4. Merge Queries: Use Home > Merge Queries to: Merge Tab1 and Tab2 using Date as the key. Merge with Tab3 using CountryCode as the key.

  5. Apply Changes: Click Close & Apply to load data into Power BI.

  6. Set Relationships: In Model View, ensure relationships: Tab1 ↔ Tab2 on Date. Tab1/Tab2 ↔ Tab3 on CountryCode.

Code :

let
Source = Excel.Workbook(File.Contents("C:\YourFilePath\YourFile.xlsx"), null, true),
Tab1_Sheet = Source{[Name="Tab1"]}[Content],
PromotedHeaders = Table.PromoteHeaders(Tab1_Sheet, [PromoteAllScalars=true]),
SelectedColumns = Table.SelectColumns(PromotedHeaders, {"Date", "CountryCode", "Sales"}),
FilteredRows = Table.SelectRows(SelectedColumns, each [Sales] > 0)
in
FilteredRows

 

 


Did it work? ✔ Give a Kudo • Mark as Solution – help others too!
danextian
Super User
Super User

Hi @Mackac2004 

As always, please provide a sample data - a copy of your excel file with confidential data removed stored somewhere in the cloud - and your expected result from that.

 

 





Dane Belarmino | Microsoft MVP | Proud to be a Super User!

Did I answer your question? Mark my post as a solution!


"Tell me and I’ll forget; show me and I may remember; involve me and I’ll understand."
Need Power BI consultation, get in touch with me on LinkedIn or hire me on UpWork.
Learn with me on YouTube @DAXJutsu or follow my page on Facebook @DAXJutsuPBI.

Helpful resources

Announcements
July 2025 community update carousel

Fabric Community Update - July 2025

Find out what's new and trending in the Fabric community.

July PBI25 Carousel

Power BI Monthly Update - July 2025

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

Top Solution Authors