syntax for merging two tables without column - powerquery

I am merging two tables where I have 3 conditions to match. But one of them is not the column but only text as "320" for the column "Hesap Grubu".
#"Merged Queries" = Table.NestedJoin(#"Removed Duplicates",
{"FirmaID", "Hesap No", {320}},
#"Mizan Özet", {
"FirmaID", "Hesap No", "Hesap Grubu"},
"Mizan Özet", JoinKind.RightAnti),
I tried 320 and also {320} but it didnt work. Is there any proper syntax for that ?
I also tried as VAR but it is looking for the column named "320" 🤦‍♂️
HesapGrubu = "320",
Table.NestedJoin(#"Removed Duplicates", {"FirmaID", "Hesap No", HesapGrubu }
I could add one custom column to the table as 320 but i wont prefer if there is a proper syntax to solve faster...
Thanks,

Wrap the table name with Table.AddColumn (tablename, "new column", each 320) before using it

Related

Power Query to filter only numbers

I've been searching everywhere to find a way to filter a column that contains both Text and Numbers, I want to filter out the numbers only from that column.
Thanks.
Add column, custom column, potentially with one of these
= Text.Select([Column1],{"0".."9"})
=try Number.From([Column1]) otherwise "Text"
Try this:
let
//Change next line to reflect Data source
Source = Excel.CurrentWorkbook(){[Name="Table3"]}[Content],
//change next line to include all columns and their names
#"Changed Type" = Table.TransformColumnTypes(Source,{{"COLUMN", type any}}),
//Change next line to be testing the proper column
#"Numbers Only" = Table.SelectRows(#"Changed Type", each not (try Number.From([COLUMN]))[HasError]),
#"Changed Type1" = Table.TransformColumnTypes(#"Numbers Only",{{"COLUMN", type number}})
in
#"Changed Type1"

How to aggregate/group the data from one table and output the result as another table in PowerBI?

I have a Raw Data Table as shown in the screenshot below:
I want to group the data in the raw data table into the Output Table as shown in the screenshot below:
Basically the output table is counting the number of student for each understanding level in different intake. May I know how should I get the output table from the raw data table? I'm still new in Power Query, any help will be greatly appreciated!
This is what I have tried:
Code:
= Table.Group(Source, {"Intake"}, {
{"Count_Little_Understand", each Table.RowCount(Table.SelectRows(_, each ([Topic 1] = "Little Understanding"))), Int64.Type},
{"Count_General_Understanding", each Table.RowCount(Table.SelectRows(_, each ([Topic 1] = "General Understanding"))), Int64.Type},
{"Count_Good_Understand", each Table.RowCount(Table.SelectRows(_, each ([Topic 1] = "Good Understanding"))), Int64.Type},
{"Count_Fully_Understand", each Table.RowCount(Table.SelectRows(_, each ([Topic 1] = "Fully Understand"))), Int64.Type}
})
I only able to get the table by individual Topic, not sure how to include other Topic appended below and also add another extra column to label the Topic as shown in my second screenshot. Hope to get some advice/help on how should I modified the code. Thank you/1
I've rebuilt a similar but shorter table:
Now we first go into Transform (1), mark the Topic Cols (2) and Unpivot Columns (3).
Your table now looks like the following screenshot. Finally, we select the Value column (1), click on Pivot Column (2), select Employee Name (3).
Result:
You can Unpivot the Topic columns, then Pivot the Understanding column, using Count of Employee Name as the aggregate value.
Then simply reorder columns and sort rows, to suit the output you need:
#"Unpivoted Topic" = Table.UnpivotOtherColumns(#"Raw Data Table", {"Employee Name", "Intake"}, "Topic", "Understanding"),
#"Pivoted Understanding" = Table.Pivot(#"Unpivoted Topic", List.Distinct(#"Unpivoted Topic"[Understanding]), "Understanding", "Employee Name", List.NonNullCount),
#"Reordered Columns" = Table.ReorderColumns(#"Pivoted Understanding",{"Intake", "Topic", "Little Understanding", "General Understanding", "Good Understanding", "Fully Understand"}),
#"Sorted Rows" = Table.Sort(#"Reordered Columns",{{"Topic", Order.Ascending}, {"Intake", Order.Ascending}})
Output:

Is there any way how to refer actual column name as variable in Power Query

I am new to Power Query and I would like to ask more experienced people about it.
I am trying to solve problem with Text.Combine where I would like to combine together value in specific column and column name of actual cell.
Do you have any idea?
My idea is formula similar to this:
=Text.Combine({[kod], Column.Name},";")
Thank you very much for answer.
Tomas
Edit 8.12.2021:
#horseyride
I actually try fill columns automatically with data in following format where first part will be value from actual row and actual column name:
For e.g.:
8M0183:F01A0101.B in first row, second column,
8M0182:F01A0102.A in second row, first column
Table example mentioned bellow.
Thank you very much for all answers.
see if this works for you. It combines the KOD column with the column name into each null cell, for every column that is not named KOD
It finds all column not named KOD. It converts those to text. It replaces all nulls with a placeholder, here "xxx". We unpivot to get everything to just three columns. We then combine the column title and the cell contents if the cell contents is equal to the placeholder. Pivot to get back to original format
let Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
ColumnList=List.Difference(Table.ColumnNames(Source),{"KOD"}),
ConvertToText= Table.TransformColumnTypes (Source,List.Transform(ColumnList, each {_ , type text})),
ReplaceNullsWithPlaceholder = Table.ReplaceValue(ConvertToText,null,"xxx",Replacer.ReplaceValue,ColumnList),
#"Unpivoted Other Columns" = Table.UnpivotOtherColumns(ReplaceNullsWithPlaceholder, {"KOD"}, "Attribute", "Value"),
CombineColumnAndRow = Table.AddColumn(#"Unpivoted Other Columns", "Value2", each if [Value]="xxx" then [Attribute]&":"&[KOD] else [Value]),
#"Removed Columns" = Table.RemoveColumns(CombineColumnAndRow,{"Value"}),
#"Pivoted Column1" = Table.Pivot(#"Removed Columns", List.Distinct(#"Removed Columns"[Attribute]), "Attribute", "Value2")
in #"Pivoted Column1"

Excel Power Query - Remove Column if it exists, otherwise don't try

I have a calculated Column Custom = Column1 + Column2 - Column3
After the calculation, i need to delete all columns except Custom
Problem is sometimes one of the columns [Column4] does not exist in the dataset
I can have the the Custom calculate properly with "try otherwise" as in:
#"Added Custom" = Table.AddColumn(#"Previous Step", "Custom", each [Column2]+[Column3]- (try [Column4] otherwise 0)),
#"Removed Columns7" = Table.RemoveColumns(#"Added Custom",{"Column2", "Column3", "Column4"}),
This works fine, however the second step fails if [column4] doesn't exist.
So i need a way to test if [Column4] exists and remove it if it does, otherwise don't try to.
how about
#"Added Custom" = Table.AddColumn(#"Previous Step", "Custom", each [Column2]+[Column3]- (try [Column4] otherwise 0)),
#"Removed Columns" = try Table.RemoveColumns(#"Added Custom,{"Column4"}) otherwise #"Added Custom"
One way to approach this is to select the columns you want to keep rather than removing columns you don't want. This is equivalent to removing all except the columns you specify.
Alternatively, you can intersect the all of table columns with your list.
Table.RemoveColumns(
#"Added Custom",
List.Intersect(
{
Table.ColumnNames(#"Added Custom"),
{"Column2", "Column3", "Column4"}
}
)
)
Another way:
add = Table.AddColumn(Source, "Custom", each List.Sum({[Column2],[Column3],-[Column4]?})),
del = Table.RemoveColumns(add,{"Column2", "Column3", "Column4"}, 1)
If the only column you want to retain is Custom, then just use Table.SelectColumns.
If there might be other columns you want to retain, you can select them also or you can generate a list of columns to remove.
From what you write, it seems you want to remove any columns whose name starts with Column. If that is the case, here is one method:
#"Removed Columns"= Table.RemoveColumns(#"Previous Step",
List.Select(Table.ColumnNames(#"Previous Step"), each Text.StartsWith(_,"Column")))

Populate conditional column depending on column name criteria

I receive a weekly report which contains some repetition of columns. This is because it is drawn from a collection of web forms which ask similar questions to each other - let's say they all ask "Do you want to join our email list?" - but this question is stored in the source system as a separate field for each form (each form is effectively a separate table). The columns will always be consistently named - e.g. "Email_optin_1", "Email_optin_2" - so I can come up with rules to identify the columns which ask the email question. However, the number of columns may vary from week to week - one week the report might just contain "Email_optin_2", the next week it might include four such columns. (This depends on which web-forms have been used in that week). The possible values are the same in all these columns - let's say "Yes" and "No".
Each row should normally only have one of the "Email_optin" columns populated.
What I would like to do is create a single column in Power Query called "Email_Optin_FINAL", which would return "Yes" if ANY columns beginning with "Email_optin" contain a value of "Yes".
So, basically, instead of the criteria simply referring to the values in specific columns, what I would like it to do is first of all figure out which columns it needs to be looking at, and then look at the values in those columns.
Is this possible in PowerQuery?
Thanks in advance for any advice!
This would find all the columns containing Email_optin and merge them for you into a new column and remove the original columns
let Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
EmailList= List.Select(Table.ColumnNames(Source), each Text.Contains(_, "Email_optin")),
#"Merged Columns" = Table.CombineColumns(Source,EmailList,Combiner.CombineTextByDelimiter("", QuoteStyle.None),"Merged")
in #"Merged Columns"
This would find all the columns containing Email_optin and merge them for you into a new column and preserve the original columns
let Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
Index= Table.AddIndexColumn(Source, "Index", 0, 1),
EmailList= List.Select(Table.ColumnNames(Index), each Text.Contains(_, "Email_optin")),
Merged = Table.CombineColumns(Index,EmailList,Combiner.CombineTextByDelimiter("", QuoteStyle.None),"Merged"),
#"Merged Queries" = Table.NestedJoin(Index,{"Index"},Merged,{"Index"},"Merged",JoinKind.LeftOuter),
#"Expanded Table2" = Table.ExpandTableColumn(#"Merged Queries", "Merged", {"Merged"}, {"Merged"}),
#"Removed Columns" = Table.RemoveColumns(#"Expanded Table2",{"Index"})
in #"Removed Columns"
you can then filter for "YES" among the merged answers if you want

Resources