What does the Expression means ?
Similar to function in Excel or DAX
which have formula inputs, arguments and deliver values.
Example:
ii. Text.Combine({43,”is”,”Rad!”}, “ “) = “43 is Rad!”
All queries in PQ start and end with
Let
in
You can------------------------ in your query, including steps that were several steps back.
reference any of the previous steps or other queries
how to right comments in PQ
ONE LINE => //YOUR COMMENT
2 OR MORE LINES => /*
*/
how to hard code LIST in PQ ?
={1,2,3}
how to hard code RECORDin PQ ?
=[Name = "walid", Age = 30]
what does Field Access Operator mean ?
=Number.Round([Sales Amount],2)
[Sales Amount] is the Field Name that contains the number we want to round.
When we drill down a specific column in the table, the result will return as
List
Syntax like {1..43} returns
to create a list of numbers from 1 to 43
how to hard code the table in PQ ?
#table(type table [Rad = text, Amount = number],{{"Yes",4},{"No",-3}})
Power Query will define a Primary Key in a Table in these situations
i. If you use Remove Duplicates (Table.Distinct function).
ii. If you are connected to a database like an SQL database and a Primary Key has been defined.
iii. If you use Table.AddKey function. Table.AddKey(table as table, columns as list, isPrimary as logical)
iv. When you use Excel.CurrentWorkbook() Function.
how do we check if the table in PQ has Primery Key ?
1- Table.keys
2- drill down any value in the table and check the result
As a Field Access Operator
[ ] will allow us to lookup an entire column, or an item in a column.
As a Lookup Operator
[ ] will allow us to do a Boolean operation to look an item up in a column, to then get a Row Index Number.
What is the general role of table look in PQ ?
TableName{RowIndex or KeyMatch}[Field Name]
How to look up an item from the list ?
{43,86}{0} = 43
How to look up an entire ROW from table ?
Table{RowIndex or KeyMatch}
If the result of this function Source{[Product=”Sunshine”]} yield an error, what is the reason ?
- Sunshine appears more than once
- Sunshine is not in the column
{43,86}{0} =
43
{43,86}{2} =
error
{43,86}{2}? =
null
Source{[Product=”Aspen”]}? NOTE : Aspen is not in the column
will return a null rather than an error if no match.
=Excel.CurrentWorkbook(){[Name=”fSales”]}
This returns a record with a table in it
M Code: = Source[Units]
will lookup the whole Units column from the table named Source and deliver it as a list
= ChangedType{0}[Product] what is the result ?
Will return the intersect value
= Table{RowIndex}[[FieldName],[FieldName2]] what is the result ?
fields specified for that ROW as records
= Table{RowIndex}[[FieldName],[FieldName2]]? what is the result if FieldName2 doesn't exist ?
fields specified for that ROW as records and last field with null value
= Table[[FieldName],[FieldName2]] what is the result ?
fields specified as table
Table[[FieldName],[FieldName2],[FieldName3]]? what is the result if FieldName3 doesn't exist ?
fields specified as table and FieldName3 contains null value
What is the difference between Function value and Parameter function ?
- Function value is a reusable function that can be invoked, example
( a as number , y as number ) as number => a+y
- Parameter function is similar to what was used in the intermediate step when the tables are not clean, so we can't append directly, it means function with transformational steps that produce a table.
(InputeTable) here we defined one ( or more ) variables which will be used in the below transformational steps =>
let
#"Transposed Table" = Table.Transpose(InputeTable),
.
.
.
.
.
.
in
#"Changed Type"
= 43 is text , what is the result ?
FALSE
= 43 is number , what is the result ?
TRUE
how to hard code date in PQ ?
#date(year,month,day)
how to hard code datetime in PQ ?
#datetime(Year,Month,Day, Hour,Minute,Second)
how to hard code duration in PQ ?
#duration(Day,Hours,Minute,Second)
if we find the Query takes too much time to update , try ----
Table.buffer
How to pivot table in PQ with multiple results like Count and Amount
Do one table for count and other for Amount (by duplicate) then merge and reorder and do what ever you want.
What is the importance of intermediate table (date table) in PQ
To make sure that whenever we make a report to a specific period (monthly basis, quarterly basis, annual basis) we are including each day that exist in the specified period.
this applies to all report you do in any tool.
When we transform from daily f table to monthly
Days changed to the beginning of month, Month and Year still same
When we transform from monthly f table to quarterly
Months will change to quarters, years still same
What is the most important thing to do if you need to make a PERIODIC report totally using PQ ?
- Create a date table for the need period
- cross join the date table with another factor/s (example Products)
Steps of creating a date table in PQ
1- reference the F table into new Query
2- sort ascending
3- extract the Min & Max
4- create Date List by days
5- transform from daily to monthly or quarterly as per your requirements or keep it daily
6- remove duplicates
When do we need to amend the period of the original F table ?
When we need to merge the Date table with the F table, so the period need to match (monthly = monthly, daily = daily, quarterly = quarterly)
What is to memorize when put a whole table into one cell ?
It is very similar to what happening in Pivot Tables where in each row in PT tables where filtered behind the scene and make a measure like SUM or AVG