Power Query Tutorial
Power Query Tutorial
Power Query if statements are a bit different to writing IF formulas in Excel, but once
you get the hang of them theyre pretty easy. In fact, the Power Query versions of IF
OR, and IF AND are even easier than the Excel equivalents.
Note: this tutorial assumes you already know how to write Excel IF, IF(OR and IF(AND
formulas. If you dont then here are the links to tutorials on IF formulas and IF(OR and
IF(AND formulas. It also assumes youre familiar with loading data into Power Query
and adding Custom Columns. If not then you can learn Power Query here or here.
Ok, lets look at an example; below we have some Orders data in Power Query.
We want to add a Delivery Status column to indicate whether the order has been
delivered.
The logic in English is, if the delivery date column is not blank, then the order has
been Completed.
Notice how you can read the if line in the dialog box and it actually makes sense in
English?
2
Digression: Maybe one day Excel formulas will catch up and well be blessed with a
similar dialog box.
And were back; after clicking OK we now have a new column for the Delivery Status:
And if you inspect the M code in the Advanced Editor you can see the formula below
has been written for you:
So, you can see that a regular Power Query if statement is dead easy to create with
the Conditional Column GUI.
Unfortunately you cant use the Conditional Column for every if scenario. Sometimes
youll have to use the Add Custom Column dialog box (see next example), and write
them yourself. In which case you should be aware of the key differences to the Excel
IF Statement, namely:
3
Power Query if or Statements
Did you notice that the example above doesnt allow for customers who come into the
store and collect their own orders? These are the In Store Pickup order types.
The logic in English is: if the delivery date column is not blank OR the Order Type is
In Store Pickup, then the order has been Completed.
Unfortunately there isnt a nice GUI to help us write the if or statement so in this case
we use the Add Column tab > Add Custom Column button:
The dialog box opens and you have to give your column a name and then type your
formula into the Custom column formula: field:
4
Lets look at the formula more closely:
If the Delivery Date is not blank or the Order Type is In store Pickup then return
Completedotherwise leave the cell blank
5
We want to add a column to calculate bonuses for the Executive level employees.
The logic in English is: if the Level is Executive AND the Target Met is Yes, then
calculate the bonus as Salary x 5%, otherwise zero bonus.
As with the if or statement, we have to use the Add Column > Add Custom Column
dialog box to write this formula:
And you can see the results in the Bonus column below:
6
Holdup, what about bonuses for the Managers? Actually, the managers get 10%
bonus if they meet their targets.
The key is to put the next if statement after the first else. Ive wrapped the formula
onto two lines so its easier to see the nesting. You can continue nesting ifs after each
else.
Or if you prefer to learn over a longer time period when it suits you please check out
my Power Query course.
And click here for more Power Query tutorials on our blog.
7
CONSULTAS CON POWER QUERY
Nota: este tutorial asume que ya sabe cmo escribir Excel SI, SI (O y Si (y frmulas Si
no lo hace, entonces aqu estn los enlaces a tutoriales sobre. SI frmulas y SI (O y Si
(y frmulas Tambin. se supone que est familiarizado con la carga de datos en la
energa de consultas y la adicin de columnas personalizadas. Si no, entonces usted
puede aprender de alimentacin de consulta aqu o aqu.
Queremos agregar una columna "Estado de entrega" para indicar si el pedido ha sido
entregado.
8
La lgica en Ingls es , si la columna de la fecha de entrega no est en blanco,
entonces el orden se ha completado.
9
Observe cmo se puede leer la lnea "si" en el cuadro de dilogo y que en realidad
tiene sentido en Ingls?
Y estamos de vuelta; despus de hacer clic en "Aceptar" ahora tenemos una nueva
columna para el Estado de Entrega:
Por lo tanto, se puede ver que una consulta de alimentacin regular si la declaracin
est muerto fcil de crear con la GUI Columna condicional.
10
usted debe ser consciente de las diferencias clave a la Declaracin de Excel SI, a
saber:
11
El cuadro de dilogo se abrir y le tiene que dar su columna un nombre y despus
escriba su frmula en la "frmula de columna personalizada: 'campo:
12
Si la fecha de entrega no est en blanco o el tipo de orden es "En la tienda de
recogida ' y luego volver' Completado ' lo contrario, deje la celda en blanco
Queremos aadir una columna para el clculo de las primas para los empleados de
nivel ejecutivo.
Al igual que con el "si o" declaracin, tenemos que utilizar la opcin Agregar
Columna> cuadro de dilogo Columna personalizada Aadir a escribir esta frmula:
13
si [nivel] = "Ejecutivo" y [Objetivo alcanzado] = "S", entonces
[salario] * 0,05 dems 0
Atraco, qu pasa con los bonos para los Administradores? En realidad, los gerentes
obtienen un 10% de bonificacin si cumplen sus objetivos.
Y la frmula es:
14
Ms de consultas de energa
Si tienes 4 horas libres el 16 de noviembre y 17 entonces le recomendamos que
consulte a cabo este curso de alimentacin de consulta por su compaero de MVP
Ken Puls y Miguel Escobar. Inscribirse antes del 11 de noviembre y utilizar LAST2016
cupn para obtener 15% de descuento .
15