Guest post by Lars Schreiber
Hello PowerPivot Community,
I’m quite sure most of you know a scenario comparable to the one in the following figure:
Two scenarios (in two tables) – in this case actuals and budget – have to be put together to do some math on them. The only problem you have is the different level of planning regarding the time dimension. While the actual figures are on daily basis, the budget was planned on monthly basis. As you could learn on this website many times before (e.g. here) you need another lookup-table with a unique list of months to bring both tables (actual & budget) together. And this is where Power Query can help you a lot.
Two ways to get your list of unique values without using Power Query
- Take a hardcopy of this unique-list into an excel-sheet and link this list into your PowerPivot-model
- For those of you, who are familiar with SQL and databases, use a database to import the table ‘Dim_Time’ and put a view/ query on it, using ‘SELECT DISTINCT’- or ‘GROUP BY’-statements and connect your PowerPivot-model to that view/ query to get the table ‘Dim_UniqueMonths’.
Version 1 needs no database-professional and no database-license, but the list of unique month-values isn’t dynamic. A change in your input data has no effect on the PowerPivot-model. This is why Version 2 should be preferred. Putting a query on dynamically changing data secures that you always have the correct list of unique values. BUT you need a database and someone (if not you) who knows to deal with it.
Get your dynamic list of unique values with Power Query
Power Query offers a third version to get your unique list of lookup-data, which combines the positive effects of version 1 and 2:
After you installed Power Query on your Computer (download available here) you can import data from a huge amount of different data sources.
Next import the csv-file ‘Dim_Time’, which has all the required months, but not unique as you need it.
Power Query automatically splits up the csv-file into different columns. For your PowerPivot-model you want to have a unique list of months, so you have to delete all the other columns from the imported csv-file, before you can start to remove the duplicates. Therefore just mark the month-column (the only one you need), do a right click into the header and choose “Remove Others”.
Now remove the duplicates and give the query a meaningful name (e.g. ‘PQ_UniqueMonths’). To rename the query just change the name under ‘properties – name’.
Now you’ve got everything you wanted. Before you save the query, go under properties and deselect ‘load to workbook’, because you don’t need the data within the Excel sheet. You want it directly in your PowerPivot-model.
Back in your PowerPivot-window go to ‘Existing Connections’ and choose your defined Power Query-query ‘PQ_UniqueMonths’. Then press ‘Open’ and PowerPivot will import these data into a new sheet within your PowerPivot-model. Give this sheet a meaningsful name (e.g. ‘Dim_UniqueMonths’) and link it to the other tables as shown in the first figure of this post.
From now on you simply have to refresh your PowerPivot-model and the unique list of months is always up-to-date.