I've imported a pdf file into power query. On a few of rows, the data has shifted 1 cell to the right and one those rows they are now not in the correct column. I can fix it in Excel, but is there a way to fix it in power query?
I ran into a similar challenge where the header row was displaced by one column when the exporting PDF content output to CSV.
I used the following strategy in Power Query:
Convert the affected row/record to a list.
Split it and reassemble it, i.e., sort it in the correct order.
Convert it back to a record and insert it back into the table.
Remove the old record
It looks something like this:
let
Source = Excel.CurrentWorkbook(){[Name="tblShiftLeft"]}[Content], // Fetches the table/range containing the row data that needs to be shifted.
#"Shifted Headers" = List.Combine({List.RemoveFirstN(Record.ToList(Source{0}),1), {""}}), // converts to list, splits, and reassembles
#"New Headers" = Record.FromList(#"Shifted Headers",Table.ColumnNames(Source)), // Creates a record from the list using the column names
#"New Headers Added" = Table.InsertRows(Source,1,{#"New Headers"}), // Insert the newly poisitioned header row.
#"Headers Adjusted" = Table.RemoveRows(#"New Headers Added",0) // Remove the old row
in
#"Headers Adjusted"
Hope this helps,
Related
I want to move a single value from column B to column A, how can I achieve it in the most simplest way in Power Query / Query Editor (Power BI)?
Please see attached images.
I know I might need to declare a variable so please enlighten me. By the way, I will delete row 1 afterwards, promote my headers, and rename column2 as PERIOD.
Thank you.
This might be along the lines of what you want to do.
If I start with this table named as Table1:
Then I click on the fx to the left of the formula bar:
And type = Table.InsertRows(Source, Table.RowCount(Source), {[Column2 = Source[KP20 rate]{0}, KP20 rate = null, Column4 = null]}) into the formula bar:
I used Table.InsertRows to create a new row in Table1. Source is the name of the latest state of Table1 after it is pulled into Power Query and before I do this step. So I actually use Source as the name of the table for this step instead of Table1. (Each applied step basically results in its own table. You probably know this already, but others may not.) So for this step I use Source as the table name in the Table.InsertRows statement. Then, since I want the new row to appear at the bottom of Source, I just enter the Table.RowCount of Source as the row number location for the new row. Then I enter each of the Columns' names and their values to be added. For Column2, I entered the value "Source[KP20 rate]{0}." Source[KP20 rate]{0} basically treats column KP20 rate as a list, where {0} serves as a pointer to the first item in the list. To target the second item in Source[KP20 rate] you would use Source[KP20 rate]{1}. You can see that I set the values for the other two columns (KP20 rate and Column4) to null.
The result:
Here's the M code in case you want to see it:
let
Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
Custom1 = Table.InsertRows(Source, Table.RowCount(Source), {[Column2 = Source[KP20 rate]{0}, KP20 rate = null, Column4 = null]})
in
Custom1
I have my data source something like below.
I need to show output in the report as below.
I tried using the unpivot column and getting something like this, how to count the occurrence value of each Business value.
Plot following mesure against Value column (from your unpivot table):
Business Occurance = COUNTROWS('your unpivot table')
We have to remove the Attribute column as the next step to Unpivot. Then my table should be looks like this.
Now create a new table with following Dax function, let's say the current table as Business Data (Your Unpivot table)
Occurrence Table = DISTINCT('Business Data')
Now end result table should look like this,
You can make use of this table for your table visual in the report.
Note: You can add n-number of rows and column into your source table and this logic will do magic to get the correct result.
I have marked two places first marked place you have to add Value column then click second marked place one dropdown value is open click count menu
Having imported an excel sheet into power query, I need to tidy it up by changing the value of a particular cell.
At the moment that cell has a null value, but there are other null values in the same column that I do not want to change. – So I cannot replace all of the null values in that column with another value.
I also cannot correct that particular cell in the source excel file (there are hundreds of them, which were created before I arrived).
I basically need some syntax for example that sets the value of cell H2 to “Jeep”, but not to change any other cells.
Very grateful for any insight.
One way would be:
In the Power Query Editor:
Add an index column starting from 1 (tab Add Column)
Add a Conditional column: If [Index] = 2 then Jeep else [H] (tab Add Column)
Delete Index column and [H] Column
Rename Custom column to [H].
Trying to create a new query from the existing "Master" Query using below formula:
let
Source = Table.SelectColumns('Original Source Name',{'Column Name','Column Name2'})
in
Source
which works fine, however I am looking to see if there is any other formula which would do the same but in a way that it will create the new query with a range of columns , for example Column 30- 67 ( in this case when the original Excel file is updated, inserting a column in this range it would automatically update in the PBI too when refreshed)
Here's one possible way. If you start with this table, named Table1:
You can reference it in a new query like this:
let
Source = Table.SelectColumns(Table1, List.Range(Table.ColumnNames(Table1), 2, 3))
in
Source
...to get this:
The formula selects a range of columns from the table starting at the column at index position 2, and spanning 3 columns. (The index starts with 0.) For columns 30-67, you would change the 2 to 31 and the 3 to 37. You would change Table1 to your Original Source Name as well.
See these links for more info on List.Range and Table.ColumnNames.
I have used folder data source in Power BI
the files are excel files with same structure
each one of these files have columns names are first
when I load the data I get the column name as row although i clicked in the
"Use First row as header" button
how can I remove first row from all files.
I may end with 100s of files in that folder, so I cant remove them one by one
I had similar problem to solve. I found answer here:
https://powerbi.tips/2016/08/load-multiple-excel-xlsx-files/
The logic is:
When you get data from Excel file, you have column Date with value Table for each sheet.
Refer to Data column, not expanding it. Add new column:
= Table.AddColumn(#"Previous Step", "TablesWithHeaders", each Table.PromoteHeaders([Data], [PromoteAllScalars=true]))
Expand column TablesWithHeaders.
Sample data:
You can apply a text filter on Column1 to filter out the values.
Results:
Assume that you don't have a useful row of data where the value is coincidentally
Column1 for Column1.
M query FYR:
#"Filtered Rows" = Table.SelectRows(#"Your Previous Steps", each [Column1] <> "Column1")