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

Find everything you need to get certified on Fabric—skills challenges, live sessions, exam prep, role guidance, and more. Get started

Reply
Anonymous
Not applicable

POWER BI is duplicating rows after loading in POWER QUERY

Hello 😀

 

I am very new to using Power BI and have self taught myself it using forums and youtube videos.

I need some help, please as I can't seem to find a solution!

In my raw data I have one row

 

hash86_3-1648563985683.png

 

But when i look at it in power query it has duplicated the row. This is happening to only a few random rows and not every single row. 

hash86_4-1648564037416.png

Any help will be greatly apperciated.

 

Thank you!

 

1 ACCEPTED SOLUTION

Hi @Anonymous ,

 

Yes, that's perfect, thanks.

 

My guess is that the three merges you are doing in your main query are introducing crossjoins and therefore duplicating rows.

 

To identify your issue, pick one of the duplicated rows (such as the one in your original example screenshot) and check each source value against the merged table, like this:

 

1) Take the [Date] value in your duplicated row (04/03/2022 in this example) and filter Codes[Date] by this value. How many rows are there with this [Date] value?

2) Take the [Store] value (9001) and filter Store[Store Code] by this value. How many rows are there?

3) Take the [TM ID] value (814497) and filter TM[ID] by this value. How many rows are there?

 

If the answer to any/all of the questions above is "more than one", then it is the merges that are creating the duplicate rows.

 

Pete



Now accepting Kudos! If my post helped you, why not give it a thumbs-up?

Proud to be a Datanaut!




View solution in original post

5 REPLIES 5
BA_Pete
Super User
Super User

Hi @Anonymous ,

 

The fact that you have a [Source.Name] column in your output tells me that you've probably missed some information in your post about how you have imported the data into your query.

 

Can you give details around what method you've used to get your source data into PBI please i.e. have you used the folder connector, by any chance?

 

Pete

 

 



Now accepting Kudos! If my post helped you, why not give it a thumbs-up?

Proud to be a Datanaut!




Anonymous
Not applicable

Hi @BA_Pete

 

As I have two seperate excel files which I need as 1 file I used the Get Data icon and selected a folder and combined both files (the headers are the same)

 

Thank you

 

hash86_0-1648566323824.png

 

 

 

 

 

Ok. For just two files I wouldn't generally recommend using the folder connector as it can get more complicated than it's worth, but we'll see if we can fix it as it is.

 

Can you select the following two queries, open Advanced Editor and copy the whole M code in each, then paste each into a separate code window ( </> button above ) here please?

 

Queries to copy/paste:

- 'Transform Sample File From X' - this is so I can see whether your generic transformation is creating duplicates.

- Your main query that is produced by the Combine & Transform process - this is so I can see whether there's a step that's been added after the C&T process has completed that's causing your issue.

 

Thanks,

 

Pete



Now accepting Kudos! If my post helped you, why not give it a thumbs-up?

Proud to be a Datanaut!




Anonymous
Not applicable

this is the code from the main query 

 

Source = Folder.Files("C:\Oxford Street\Business Insights & Information\Reporting\Appointment Dashboard\2022-23\Other Appts\New folder\Appt Paste"),
#"Filtered Hidden Files1" = Table.SelectRows(Source, each [Attributes]?[Hidden]? <> true),
#"Invoke Custom Function1" = Table.AddColumn(#"Filtered Hidden Files1", "Transform File", each #"Transform File"([Content])),
#"Renamed Columns1" = Table.RenameColumns(#"Invoke Custom Function1", {"Name", "Source.Name"}),
#"Removed Other Columns1" = Table.SelectColumns(#"Renamed Columns1", {"Source.Name", "Transform File"}),
#"Expanded Table Column1" = Table.ExpandTableColumn(#"Removed Other Columns1", "Transform File", Table.ColumnNames(#"Transform File"(#"Sample File"))),
#"Changed Type" = Table.TransformColumnTypes(#"Expanded Table Column1",{{"Source.Name", type text}, {"Date", type date}, {"Store", Int64.Type}, {"Salesperson", Int64.Type}, {"Name", type text}, {"Type", type text}, {"Dept", type text}, {"Transaction", Int64.Type}, {"£ Sales", type number}, {"Unit Sales", Int64.Type}, {"Column10", type any}, {"Column11", type any}, {"Column12", type any}}),
#"Removed Columns" = Table.RemoveColumns(#"Changed Type",{"Column10", "Column11", "Column12"}),
#"Merged Queries" = Table.NestedJoin(#"Removed Columns", {"Date"}, Codes, {"Date"}, "Codes", JoinKind.LeftOuter),
#"Merged Queries1" = Table.NestedJoin(#"Merged Queries", {"Store"}, Store, {"Store Code"}, "Store.1", JoinKind.LeftOuter),
#"Expanded Store.1" = Table.ExpandTableColumn(#"Merged Queries1", "Store.1", {"Store Name", "Storeindex"}, {"Store Name", "Storeindex"}),
#"Expanded Codes" = Table.ExpandTableColumn(#"Expanded Store.1", "Codes", {"Week", "Period", "Year", "Dept Code", "Day", "Date - Copy"}, {"Week", "Period", "Year", "Dept Code", "Day", "Date - Copy"}),
#"Renamed Columns" = Table.RenameColumns(#"Expanded Codes",{{"£ Sales", "Sales"}, {"Unit Sales", "Units"}, {"Transaction", "# of Appts"}, {"Salesperson", "TM ID"}, {"Name", "TM Name"}, {"Date - Copy", "Dayindex"}}),
#"Merged Queries2" = Table.NestedJoin(#"Renamed Columns", {"TM ID"}, TM, {"ID"}, "TM", JoinKind.LeftOuter),
#"Expanded TM" = Table.ExpandTableColumn(#"Merged Queries2", "TM", {"Bucket", "Beauty Brands"}, {"Bucket", "Beauty Brands"}),
#"Filtered Rows" = Table.SelectRows(#"Expanded TM", each ([Week] = 5) and ([TM ID] = 814497))
in
#"Filtered Rows"

 

 

and this is the code for the Transform file

 

let
Source = Excel.Workbook(Parameter1, null, true),
#"Appt Paste_Sheet" = Source{[Item="Appt Paste",Kind="Sheet"]}[Data],
#"Promoted Headers" = Table.PromoteHeaders(#"Appt Paste_Sheet", [PromoteAllScalars=true])
in
#"Promoted Headers"

 

 

is this what you needed?

 

Thank you 

Hi @Anonymous ,

 

Yes, that's perfect, thanks.

 

My guess is that the three merges you are doing in your main query are introducing crossjoins and therefore duplicating rows.

 

To identify your issue, pick one of the duplicated rows (such as the one in your original example screenshot) and check each source value against the merged table, like this:

 

1) Take the [Date] value in your duplicated row (04/03/2022 in this example) and filter Codes[Date] by this value. How many rows are there with this [Date] value?

2) Take the [Store] value (9001) and filter Store[Store Code] by this value. How many rows are there?

3) Take the [TM ID] value (814497) and filter TM[ID] by this value. How many rows are there?

 

If the answer to any/all of the questions above is "more than one", then it is the merges that are creating the duplicate rows.

 

Pete



Now accepting Kudos! If my post helped you, why not give it a thumbs-up?

Proud to be a Datanaut!




Helpful resources

Announcements
Europe Fabric Conference

Europe’s largest Microsoft Fabric Community Conference

Join the community in Stockholm for expert Microsoft Fabric learning including a very exciting keynote from Arun Ulag, Corporate Vice President, Azure Data.

Power BI Carousel June 2024

Power BI Monthly Update - June 2024

Check out the June 2024 Power BI update to learn about new features.

RTI Forums Carousel3

New forum boards available in Real-Time Intelligence.

Ask questions in Eventhouse and KQL, Eventstream, and Reflex.

Top Solution Authors
Top Kudoed Authors