Power BI | Query editor exercise | Unpivoting data and changing the data source

This exercise is provided to allow potential course delegates to choose the correct Wise Owl Microsoft training course, and may not be reproduced in whole or in part in any format without the prior written consent of Wise Owl.

Software ==> Power BI  (111 exercises)
Version ==> Latest update
Topic ==> Query editor  (8 exercises)
Level ==> Harder than average
Subject ==> Power BI training
Before you can do this exercise, you'll need to download and unzip this file (if you have any problems doing this, click here for help).

You need a minimum screen resolution of about 700 pixels width to see our exercises. This is because they contain diagrams and tables which would not be viewable easily on a mobile phone or small laptop. Please use a larger tablet, notebook or desktop computer, or change your screen resolution settings.

This exercise covers unpivoting data, changing data sources and more besides!  To begin with, create a new report and load the data in the First Half.xlsx workbook.

User Query Editor to tidy up this data so that you have something like this:

First half of year

You'll need to remove the top row, then make the new top row into the row headers.

Choose the following option to unpivot the monthly data:

Unpivoting data

Choose to unpivot the months of data.

After a bit of renaming, you should have this table in Power BI:

Start of the table

The start of the table of unpivoted data.


Use this to create a chart showing value by month:

Value by month

The problem is that we want to sort the months correctly, but to do that you'll need to assign numbers to them.


Go back to Query Editor and add a conditional column:

Conditional column

The option to add a conditional column, returning the correct month number for each row.


This should give you something like this:

Month number

After painstakingly typing in the 6 possible conditions and results, you should have a column turning a month name into a number.


You might have found it easier to do a couple of conditions then edit the M formula for this step to add the other four (it's certainly worth having a look at it to see how easy it is to understand and amend).

You can now choose to sort your month names by number:

Sorting months by number

Choose this option to sort your month names correctly.

After checking your chart is sorting by the correct column, you should now have this!

Sorted chart

The same chart, but with the correct sort order.


Oh dear - Wise Owl can only apologise.  The exercise asked you to link to the wrong file.  Change your M to refer to the file called Second half.xlsx (you'll need to go down your query steps making lots of editing changes to resolve errors), then check your chart still works:

Second half chart

After a lot of retyping in your query step formulae you should eventually get this chart!


Save your report as The knees of a bee, then close it down.

You can unzip this file to see the answers to this exercise, although please remember this is for your personal use only.
This page has 0 threads Add post