Showing posts with label Best Practice. Show all posts
Showing posts with label Best Practice. Show all posts

Hire a PowerBI guru

I've recently hired a PowerBI analyst to join my team in my full-time industry job. In 3 short months, he's built 3 amazing PowerBI dashboards that have given us tremendous insight in to our accounting data such as the composition of our Journal Entries, our fluctuation (flux) explanations, and our Month End Close Status. It's been a tremendous win.

He started his career as a data engineer, and then taught himself PowerBI from materials like this available online. He's already been awarded our company's high honor quarterly CFO award: the first time someone on my team has won in the last three years. I've been trying to teach accountants how to use these Power tools, but hiring someone who has already made the effort, has been a huge win. I can't wait until the market starts to have more people like him available as they are a key part of my accounting strategy for winning. 

So my key takeaway, hire a PowerBI guru if you can. Make the case; they will quickly pay for themselves with their insights (and make you look like a rockstar)!

And if you are the guru already, send me a message, and let's talk. Maybe I have a project or work that you can help me with. 

Combine all files in a Folder

Just joining the blog? Explore prior lessons here.
 
Imagine a folder with 100 journal entry files, and in less than in a minute you can combine them all together in to one report. Power Query makes it very easy to take all the files in a folder and combine the files together to create a single query. 
The biggest challenge is how to modify the query when your report changes. Let's walk through all steps, so this will also serve as a reference guide for when an inevitable change occurs in the future.

File types

For this illustration, we are going to use Trial Balances saved as Excel files all in a single folder. Reports which you frequently export from an ERP system and then manipulate for analysis are excellent files to use when trying this out initially.

While you can combine any files, it works best when:
  • The layout of the files are similar such as consistent column headers and number of columns.
  • The files are all of the same file type (i.e, .xlsx, .csv, .txt); and
  • The file layout rarely changes.
If you want to follow along, download these Trial Balances and save in a folder on your network.
                   💾↑                              ↑💾

Get Data

Let's build a query using the folder where the above downloaded files are saved. First step is to load the data. On the Excel ribbon, go to Data, Get Data, From File, From Folder. Browse to the folder where the files you downloaded above are saved.


Once selected, the navigator screen will display a list of all the files in the folder. Select Combine, then Combine & Transform Data.
Next, Power Query wants to know which file in the folder should be used as the template when combining the files. By default, the Sample File will be the First File in the folder. You can also select the option to exclude any files which have errors.



After selecting OK, Power Query has now taken all the files in the folder and combined them together.












The Helper Queries

When a folder is the source for a query, Power Query creates several Helper Queries.
    Parameter1: tells Power Query which file needs to be used as the example. 
    Sample File: grabs the file to be used as the model, or example.
    Transform File: provides instructions on how to convert the Sample to rows & columns.
    Transform Sample File: converts the Sample File in to a query with rows & columns.
    Now let's look at each of these queries to understand more about how they each perform and where challenges may be hidden.
The Parameter Query tells Power Query which file needs to be used as the example. This will always be the "Sample File"; I can't think of a single issue I've ever encountered with the Parameter Query. If something breaks, this is not likely your culprit.









The Sample File Query grabs the file which was chosen to be the example. 











The challenge which I've encountered in the past is when the first file in the folder is no longer representative of what the data should look like, such as when the source updates the file layout (frequently I see this issue with third party files). In this case, filter the Source to select the correct file to use as the template for combining the data.


The Transform File query is actually a custom function (note the fx next to the query name). When the function is ran (called invoked in Power Query), all the steps are performed as defined in the query.










Applied Steps aren't visible in a function query; instead, to view what the query is doing you'll need to select the Advanced Editor from the Home menu to view the M language behind the query. In brief, the code below is saying, transform the Sample File (Parameter1) from the file format in to the Excel Workbook format of a query, which includes columns an rows, using the data from the worksheet Sheet1. When the function is run it creates the query Transform Sample File.














The Transform File query is where you are most likely to encounter an issue. Note above that when the function runs it is looking for a worksheet named "Sheet1". If the Sample file has a different sheet name, the query will fail. To correct, simply open the Advanced Editor and replace "Sheet1" with the appropriate worksheet name from the Sample File.

A similar type of issue can occur when the files in the folder are .csv. Below is what the M language looks like when the files are csv. Notice the "Columns=5" portion of the code; this means that only the first 5 columns of the csv file will be pulled in to Power Query when the function is invoked. If your file format changes and now has 6 columns, you can simply open the Advanced Editor and change "Columns=5" to "Columns=6". This is the most frequent issue I've had with my queries from folders. Bookmarking this tip will save you time in the future.

💥BEST PRACTICE TIP
Quickly fix From File from Folder queries by making quick alterations to the queries in the Advanced Editor view. In the Transform File function query, modify the M language for Excel Files by updating the worksheet name, or for csv files update the number of columns.💥

The final Helper Query is the Transform Sample File query. This query is generated when the function query, Transform File, is invoked. It brings together all the helper queries to convert the sample in to an Excel workbook type of query.





To sum up what we've discussed:, the Helper Queries are:
    Parameter1: tells Power Query which file needs to be used as the example. 
    Sample File: grabs the file to be used as the model, or example.
    Transform File: provides instructions on how to convert the Sample to rows & columns.
    Transform Sample File: converts the Sample File in to a query with rows & columns.


The Converted File

After all the Helper Queries are created, then the final query is created. This query is the end result we were trying to achieve. In this query, you'll perform the normal Power Query transformations such as data clean-up and modifying columns and headers, achieving an end result similar to below, which combines trial balances from multiple dates.






First note that all the Applied Steps in the screenshot below were automatically created by Power Query. The first step is the source, which is the folder file. Then, Power Query filters for any hidden files. Third, it invokes the function query, Transform File, transforming all the files to Excel workbook query types adding a column called Transform File. It then formats the file like the Sample File by renaming the Header Name to Source.File and removing extra columns. Finally, it expands the transformed data and changes the types.



Power Query's ability to Combine all files in a folder is revolutionary. It's allowed me to personally create queries and analyze data in ways I never imagined before learning about it. While extremely easy to implement, when it fails, the existence of 4 Helper Queries plus the final query, can make it hard to identify where things go wrong. 

In this lesson, you learned:
  • How to Get Data using From File From Folder;
  • What each Helper Query does; and
  • How to troubleshoot common issues.


Prior post: Query Dependencies
Next post: Direct Query

Relationship problems

Just joining the blog? Explore prior lessons on Relationships here.

Ah, relationships: they always seem to have at least some problems.

In Power Pivot, the most obvious alert to a relationship problem is when all the values in a Pivot Table are the same. 

Let's walk through a few examples illustrating how things go wrong, so you can spot and solve issues when they occur in your own data sets.

The Data

For this exercise, there are two data sets: a Costs Table and a Sign Table. Download the data file by selecting the icon above the arrow below.

                                                                   

Let's explore the data in the Tables. The Sign Table is a Lookup Table for the natural sign based on transaction type. There are the two typical accounting transaction types (debit and credit) plus an additional type, Other (for statistical transactions).
The Costs Table contains 12 accounting transactions; most transactions have a typical Transaction Type of Credit or Debit, but 2 are listed as Total and 1 is listed as Zero.
In native Excel, if you did a VLOOKUP to find the sign for the last transaction with a Transaction Type of Zero, the result would be #N/A.

How will a Power Pivot Table handle the same exercise?
How should the Pivots be set-up to obtain the correct count of transactions by type?
 

Lookup Table field as value

On the Pivots tab, 2 Pivot Tables have been built which essentially are trying to gather the same information: what is the count of the type of each transaction?  The first set is pulling in to the rows area Transactions Type from the Costs Table (Data Table). The second set is pulling in Type from the Sign Table (Lookup Table). 

Let's look first at the impact of pulling in to the values area of each Pivot Table the type from the Lookup Table (Type from the Costs Table).


Immediately noticeable is the left Pivot showing the count of Type as 3 in each row. Since Zero occurs only once in the Costs data, how can there be a count of 3? If the Grand Total is 3, how can each row also be 3? 

Power Pivot gives us a hint to why the left Pivot is returning 3 for each Transaction Type. When the Relationships alert shows up, it usually means we need to look at our relationship or in this case, build one.

Build the Relationship

The relationship error message isn't extremely helpful; selecting Auto-Detect shows "No new relationships found". Selecting Create opens a box to Create Relationship, but requires understanding which type should be the Foreign and Primary keys. I prefer instead to use the Power Pivot menu.

Let's build the relationship by going to the Power Pivot menu on the ribbon, then select Manage. Inside Power Pivot, select the Diagram View. Remember that the Data Table is the Costs Table and the Lookup Table is the Sign Table. So we'll need to have the Costs Table lookup to the Sign Table. To do so, in the Costs Table, select Transaction Type and drag over to the Sign Table Type field. This connects the two fields establishing a Relationship.
Looking at the Pivot Tables now, you'll note nothing has changed. Further exploration is required.

Data Table field as value

In the exercise above, type was pulled in to the Pivots from the Lookup Table, Sign. This returned a value of three which represents the number of types listed in the Lookup Table (Credit, Debit, Other). Each type being represented once, the Pivot on the right provided the correct count of the lookup, but not the count of the transactions by type.

Now let's pull in to each Pivot the Transaction Type from the Costs query.











Both Tables show a Count of 12. The left Pivot shows the count for Zero and Total, whereas the right Pivot only shows Blank, since those labels aren't in the Sign Table. On the surface, it seems like the left Pivot is the correct approach. 

Let's perform one more test.

The Final Test

Let's add the Sign to both Pivots.








Now this view highlights an important issue with the left Pivot. While it's not returning a result of 3 in each row of the Pivot, showing 1 as the result is also incorrect. If you were to write Measures off the Table like this, your results would be inaccurate.

Why did this return the wrong result? The cause is because the left Pivot is asking for data from the Lookup Table (Sign) and from the transaction table (Transaction Type). In Power Pivot, Lookup Tables can see in to Data Tables, but Data Tables can't see in to Lookup Tables. Regardless of the rows field, the relationship flows down from the Sign Table to the Costs Table.

When I first started using Power Pivot, I frequently had results where all rows were the incorrectly the same frustrating number. 


💥BEST PRACTICE TIP
Always use the columns from the Lookup Table, not the Data Table, as the fields in the Pivot. If the columns from the Data Table are used, the Pivot can not correctly see the Lookup Tables or other Data Tables, and the Pivot Table will return inaccurate results.💥


Now that you know the Best Practice Tip, the right approach to building these Pivots was the Pivot on the right. Since the values area includes fields from both the Lookup and Data Tables, the rows (and column) areas can only include fields from the Lookup Table.


In this lesson, you learned:
  • Always use the columns from the Lookup Table, not the Data Table, as the fields in the Pivot;
  • Always build relationships where the data table lookups to the lookup table; and
  • Just because it looks right, doesn't mean it is. Robustly test for accuracy.


Next post: Error checking

What's killing My Excel?


Across the globe, Excel crashing is an accountant or analyst's bane. I've been there and know how exhausting it can be.  Fortunately (knock on wood), I've found some tips which have virtually eliminated crashing for me.  
  • Get 64-bit Excel
  • Disable add-ins
  • Prioritize Excel
  • Check your resource monitor


Get 64-bit Excel

The #1 way to fix Excel crashing issues is to install the 64-bit version of Excel on Office 365.  

By default, IT departments across the globe install the 32-bit version of Excel on Office 365.  While that works for most, Excel's 32-bit version is not sufficient for running the more complex Excel workbooks used by finance and accounting teams.  See this Microsoft Office article about why multiple Pivot Tables, slicers and VLOOKUPs can constrain your Excel resources.   

Finance and Accounting users are frequently the largest Excel consumers, but your IT support team may not realize it when deploying PCs to users.  If your Finance and Accounting teams aren't using 64-bit Excel today, there may be some support team resistance to making the change and deploying 64-bit.  Historically, Microsoft Office recommended 32-bit installs by default; however, it did not apply to power users like Finance and Accounting teams.  Here's a link to another Microsoft Office article which might help persuade.

Incapability with existing add-ins, such as Hyperion Essbase, is the primary issue which may need to be addressed. 
  • First, I recommend seeing if there is a 64-bit version of your add-in.
  • If not, consider installing anyway and testing the impact.
  • If impacted, explore with your IT team other solutions, such as a 32-bit Excel version with the add-in installed inside a Citrix environment and the 64-bit Excel version on your desktop.
If you are experiencing install setbacks, don't give up; I assure you the 64-bit version is worth it.  While you wait for IT to validate add-ins, try one of the other solutions below. 


Disable Add-Ins

Excel Add-ins sometimes behave badly, especially when the version of Excel the add-in was built on and the current user version of Excel deviate.  This seems to be especially true in the Office 365 environment where updates can occur monthly.

Initially, try disabling all add-ins and turning them on only when needed.  To effectuate, in Excel go to File, Options, Add-ins, Manage, Excel Add-ins, Go.  Uncheck all the add-ins.  Next, repeat these steps, but select Manage, COM Add-ins, Go.

💥BEST PRACTICE TIP
Speed up the add-in disabling process by adding a short-cut to your Excel Quick Access Toolbar.  In Excel, go to File, Options, Quick Access Toolbar, Choose commands from: All Commands, Add-ins (the first one, which has no icon & a drop down menu). 💥

When Excel crashes, keep track of which add-ins, if any, were enabled.  Once an add-in has been identified as a culprit, work with your IT team to address.  In the meantime, whenever you need to enable the suspect add-in, save backup copies often. 

If Excel crashes at the same frequency when the add-ins are disabled, then add-ins is likely not your primary culprit; read further and see if one of the other solutions helps.


Prioritize Excel

All running applications share processor time.  Tell your computer to give Excel more love by changing the priority level.  

Use Ctrl+Alt+Del to open Task Manager.  On the Details tab, right click on Excel.exe process.  Choose Set Priority.  Then, select either High or Above Normal.  

The priority auto-resets to Normal whenever Excel is restarted making this a temporary solution at best.

While it may be tempting to choose Real Time, rumor has it that this will make your other applications jealous, your CPU's head spin, and your PC crash.  💔


Check your resource monitor

Return to Task Master.  On the bottom of the Performance tab, select "Open Resource Monitor".  This tool provides utilization visuals for the processes running on your machine.  Choose the Overview tab and keep the 4 charts open and visible while you work.  When the Resource Monitor charts are at their maximums for an extended period of time, drill down on the applicable Resource Monitor tab to try and isolate what is dragging you down.  With data in hand, partner with IT support to achieve improved performance.  

In this lesson, you learned how to eliminate Excel crashes by:
  • Installing 64-bit Excel,
  • Disabling add-ins,
  • Prioritizing Excel, and
  • Checking your resource monitor.


Prior post: Measures Inside Measures
Next post: Distinguishing datasets in Power Pivot


💬Always love hearing how others have tackled Excel performance issues.  Drop a comment below to share.

Measures inside Measures

This is the final post of the Intro to Power Pivot series.  Jump to the 1st post of the series here.


It's time to wrap up the Intro to Power Pivot series.  This post will work through writing the final three Measures (Var to Budget, Prior Year, and Var to PY).


Budget variance

Let's calculate the variance between Actual and Budget by month.

Start with the workbook created from the last exercise, Measures In-depth, or download this file.
With your cursor in the Pivot Table, go to the Power Pivot menu, and select Measures, New Measure.




In the Measure dialog box, select the Table, Actual_Data.
Change the Measure name to Var to Budget.
In the formula box, type =[Actual] - [Budget].


Start typing Actual, and you will get a drop down box to select from.
Measures have a 𝚺 sign next to them and are noted in brackets.
Press Tab to select.

Check formula.  Result should be no errors.
Format by changing the Category to Number, with 0 decimal places.
Ok.



Prior Year Measure using CALCULATE

Let's create a Prior Year Measure to show the 2012 Actual values.  The formula for creating that Measure is as follows:

= CALCULATE ( [Actual] , Date_LU[Year] = 2012 )

The CALCULATE function can filter a Measure.  The CALCULATE function requires first, the Measure, and then the filter.  The Measure is [Actual].  The filter is the 2012 year, which is pulling from the Year column of the Lookup Table, Date_LU.  Columns and Measures are in brackets.



Notice how the Prior Year column is showing the 2012 Actual numbers for both 2012 and 2013.  Using CALCULATE you've told Excel to always show the 2012 actual value regardless of the year presented in the Pivot Table. This is referred to as filter context and occurs because CALCULATE filters take precedent over Pivot Table filters


💥BEST PRACTICE TIP
CALCULATE is a very powerful function.  Always test that the results are as expected.  If others in your organization aren't using Power Pivot yet, consider adding a comment to alert the user to the CALCULATE function. 💥

Pivot

Let's do some quick clean-up before moving on to our final Measure.

In the PivotTable Fields List, move the Year field from Columns to Filters.  Filter to show only 2013.
In the Values area, move Prior Year to the top, so it is the first column in the Pivot.

Variance to Prior Year Measure 

For our final Measure, let's write the variance to the prior year.


Below is a screenshot of the final result.  

























By the time you wrote your 5th and final Measure for this Intro to Power Pivot series, hopefully, you were starting to get the flow for Measures. Keep practicing, replacing your normal SUM of Values with Measures and trying out a few CALCULATE exercises. Pretty soon Power Pivot will be second nature.

In this lesson, you learned how to:
  • Write Measures which reference other Measures;
  • Write Measures to take the difference between columns in a Pivot Table; and,
  • Use the CALCULATE formula to create filtered values.

Measures in-depth



This is the 7th post of the Intro to Power Pivot series.  Jump to the 1st post of the series here.


Below is the Pivot Table from the last exercise.  Let's create the Measure, Actual, and polish up the Table.  Then, let's talk more in-depth about Measures.

Writing the Actual Measure

Start with the workbook created from the last exercise, Measures, or download this file.

With your cursor in the Pivot Table, go to the Power Pivot menu, and select Measures, New Measure.



In the Measure dialog box, select the Table, Actual_Data.
Change the Measure name to Actual.
In the formula box, type =SUM(Actual_Data[Sales]).
Check formula.  Result should be no errors.
Format by changing the Category to Number, with 0 decimal places.
Ok.

Your Pivot Table now contains the new Measure "Actual".  You can compare to the Sum of Sales values you are accustomed to seeing and confirm the Measure resulted in the same output (just formatted).  
In the Values area of the PivotTable Fields List, remove both the Sum of Sales metrics.  Below is a snapshot of the Pivot Table, which now contains the two Measures, Budget and Actual.

Measures In-depth

With the introduction of Measures, you've unleashed a tremendous amount of calculating power, which hasn't yet been explained.  Let's revisit each element of the Measures dialog box to start digging deeper.



Table Name

The Table Name selected determines where a Measure is located on the Fields section of the PivotTable Fields List.  Note the Actual and Budget Measures in the image below.

Some people recommend placing Measures on the queries where the related data sits, which was the structure selected for this exercise.  Selecting the queries to assign a Measure to is a matter of personal preference.  The Measure will return the same result regardless of the query assigned.    

Measure Name

The Measure Name will be the default displayed name on the Pivot Table, as Budget and Actual are in our exercise.  Like a normal Pivot Table, the displayed name can be changed in Value Field Settings.  In the example below, the Measure Name would be "Actual" and the displayed name on the Pivot would be "Actual Sales".

Name your Measures something intuitive to make it clear what the Measure is calculating.  As your Data Models start to have multiple Measures, such as Actual Sales and Actual Orders, it will be helpful to easily distinguish between the two.  In our Data Model, Actual Sales and Budgeted Sales would have been more robust Measure names than Actual and Budget.

💥BEST PRACTICE TIP
Create robust Measure namesThink about possible future uses for your Data Model.  Changing a Measure name later can cause headaches.  A renamed Measure is removed from any existing Pivot Tables and requires modifying any dependent Measures.  💥


Formula

The formula area is the meat of the Measure and where the DAX language comes in to play.  Measures are calculations which display in the Values area of a Pivot Table.  As a calculation, Measures always start with an equal sign.  

=SUM(Actual_Data[Sales])

The next element is the function.  There are more than 200 DAX functions, many which resemble functions in native Excel, but give more Power to your analytics.

In our exercise, we used the function SUM.  SUM adds up the amounts in a specified column.  All functions are followed by an open and closed parenthesis: =SUM().

For the SUM function, we specified the column as Actual_Data[Sales] surrounded by open and closed parenthesis.  Since Data Models can contain multiple tables (queries) which can have the same column names (such as Sales), when specifying a column, include the table name and the column name.  Our table name was Actual_Data, and the column we are summing from that table is Sales.  Columns are referenced in brackets.

At this point, we've comparatively done a lot of work to mimic the "Sum of Sales" value normally included in a Pivot Table.  This is a simple example, designed to mimic something you are likely very familiar with to lay the foundation for more complex Measures and analysis.     

As an additional foundational exercise, I recommend reviewing the official documentation for a formula: Microsoft link.  As you venture on your own, understanding how non-accountants reference the elements of a function enhances collaboration.  

Check formula

After writing the formula, Always press "Check formula".  The green checkmark and "No errors in formula" message confirm the formula is written correctly.

A very common error message is the following, unhelpful message.
When the above message is received, check to make sure there is a closed parenthesis at the end of the formula.

Using Tab and the drop down menus can assist with dropping in the function and column names correctly.  Unlike Power Query, DAX is not case sensitive.  

Format

When viewing the Measures "Budget" and "Actual" in your Pivot Table, you may have noticed they were formatted with a comma and no decimals.  


This was based on the format settings listed in the Measure dialog box.  Each time a Measure is used, the format is set and ready to go.

In this lesson, you:
  • Practiced writing Measures;
  • Compared Measures to the traditional approach of adding Values to a Pivot;
  • Explored each component of the Measure dialog box;
  • Learned how to  write robust Measure names; and,
  • Resolved common Measure errors.

There's a lot more to talk about regarding Measures. Subscribe below to be alerted when the next post is ready.



SOLUTION


Prior post: Measures
Next post: Measures inside Measures


💬  Challenge exercise: 
Load the Actual_Data query in to PowerBI, and write the Actual Measure, =SUM(Actual_Data[Sales]).