Saturday, April 12, 2014

5 Email writing tips for analysts


In labouring to be concise, I become obscure

from Horace (poet)

 
The key task of an analyst is explain complex concepts simply. Below are 5 tips that help me write effective email messages.

Email writing tips 
  1. Start your email message with a topic sentence
  2. Use proper names instead of pronouns
  3. Provide examples if asking to decide between one option versus another option 
  4. Keep it short  
  5. Use bullet points when writing options 


1. Start your email message with a topic sentence
Most executives and decision makers view their emails on a smart phone, thus showing a preview of the  first sentence of every email. That's a perfect window to grab their with the following:

  • if you need something, make your first sentence a question. 
  • If you have something to show then state in your first sentence that "the attached file provides..."

2.  Use proper names instead of pronouns.

I suggest you forget the words he, she, we, and it (especially "we" and "it"). Replace them with proper names, objects, and concepts.  This way, the reader isn't confused about who or what you are talking about. 


3. Provide examples if asking to decide between one option versus another option

Just like ordering food from a fast food restuarant, it's nice to see options. For example, if you're asking the reader to decide if a report is to display a physician's name by [first name] [last name] or [last name], [first name]. Why not take the extra minute and provide real names from your organization. 


4. Keep it short

Busy executives and decision makers receive a lot of emails. There isn't time to read novels. State what you want in your topic sentence, provide a couple of supporting bullet points or paragraphs, and get out. If your reader needs more info, let them ask. 


5. Use bullet points when writing options

A great way to break up the monotony of an email is to use bullet points. I suggest using a maximum of three. There is something powerful in the number three. 


As I read the poet Horace's quote above, I believe that  a well written email has less "I" words and more words that describe the issue or concept.


What did I miss?

Thursday, October 24, 2013

What does an analyst do? Question, Investigate, and Communicate


“The Golden Rule of Habit Change: You can't extinguish a bad habit, you can only change it.”
Charles Duhigg, The Power of Habit: Why We Do What We Do in Life and Business


I recently read the following article, Aviate, Navigate, Communicate: Business Crisis Management From a Pilots Perspective. It struck an accord because in another life time, I was a young Student Naval Flight Officer in the U.S. Navy. The phrase, Aviate, Navigate, Communicate, is a habit drummed into aviators to utilize when an emergency happens in the air. It represents the basic activities needed to keep one alive while troubleshooting an issue. It’s a habit that requires actions and no thoughts to follow.

“Aviate, Navigate, Communicate” led me to devise “Question, Investigate, Communicate” for my profession in analytics.

Question
At the very minimum, an analyst needs to understand the business problem. Some call it requirements gathering, writing specifications, or just plainly “what’s the question?”
I like to ask the following questions:
  • What’s the issue/problem?
  • Who else needs to see this info?
  • Where do you plan to use this information? Meeting room? Smart phone?
  • What does the final output look like?
  • When is it needed?
  • How do you (business user) plan to use this info?
If the above questions look similar a journalist’s “the 5 W’s” then you’d be right. I often imagine that I’m a journalist when I’m first presented with an issue or request. I treat each request with a healthy dose of skepticism.

Investigate
Now that I know what the core problem is, I need to develop options or possible solutions.
Investigation can take on several forms such as:
  • Data extraction from databases to produce a data report 
  • ad-hoc querying against corporate data-sets to satisfy a “what if” question 
  • Descriptive statistics applied to a data-set to understand 
  • Data Visualizations in the form of charts and maps 
  • A data model created to describe a population with embedded business logic 
  • Facilitation or Negotiation with varying parties to arrive at a set of options 
I like this quote from Rahm Emanuel, “Don’t come in here and dump a problem. I have a whole desk full of those. Bring a set of solutions.” That is analysis. It attempts to distill a problem to core components and offers various thoughts on how to describe or solve the problem

Communicate
No matter how brilliant a piece of analysis is, without communicating the results to the right person at the right time then analysis isn’t complete. Communication is actually the cornerstone to great analysis. Think about it, the task of analysis is to dissect key facts from vast amounts of information and transform it into useful “bit-size and flavorful” bites.

Communicating results can take on many forms:
  • report/dashboard
  • excel model
  • e-mail/memo
  • presentation in a meeting
  • phone call/Face-to-face interaction
 No matter the form, one must be mindful to how much or how little information to give to the business user.

When the stress level is high and time is short, remember to “Question, Analyze, and Communicate”

Monday, August 26, 2013

Print multiple Excel worksheets to PDF using VBA

 

“Excel developers realize that the most efficient and maintainable applications are those that make the most of Excel’s built-in functionality,augmented by VBA where appropriate.

from Professional Excel Development by Rob Bovey, Dennis Wallentin, Stephen Bullen, and John Green



After completing a multiple worksheet Excel model, my business user requested the reports in PDF format. Great! There goes my morning I thought. How to do I create a VBA routine to convert the multiple Excel worksheets into a single PDF file? Google it!


My 10 minute google search offered no quick solutions. Suddenly, I stopped looking for a VBA solution. The above quote flashed through my mind. Excel more often than not can do what you want without writing new VBA code. It’s the old adage, “if all you have is a hammer, everything looks like a nail”


I only needed 5 PDF files. Why not use Excel to simply produce the files manually. I did the following:

  • Set the print area for all 3 worksheets with a 3-line VBA code snippet

  • In Excel’s Developer ribbon, click the “Record Macro” button

  • Select the three worksheets by holding down the CTRL key while clicking each worksheet with the mouse left button.

  • Go the Excel’s back page by navigating to the File ribbon

  • Click “Save & Send”

  • Click “Create PDF/XPS Document”

  • Click “Create PDF/XPS”

  • Enter your file name of choice and click the “Publish” button

  • In Excel’s Developer ribbon, click the “Stop Recording” button


That’s a lot of clicks to create a 5 PDF files. Anyway, I was able to print the reports. Being the Excel junkie that I am, I couldn’t help but create a VBA routine to avoid all those clicks. 


It turns out the answer to automating came from the Excel’s Macro recorder. I opened the VBA editor (ALT-F11) to see the following code created by Excel:

  Sheets(Array("Sheet1", "Sheet2 ", "Sheet3")).Select

   Sheets("Sheet1").Activate

   ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, Filename:= _

       "C:]\test.pdf" _

       , Quality:=xlQualityStandard, IncludeDocProperties:=True, IgnorePrintAreas _

       :=False, OpenAfterPublish:=True

The key was selecting the three worksheets programmatically. It also provided the syntax to create a PDF file.


TIP: Use Excel’s Macro recorder to discover VBA objects and collections. It writes horrible code but provides really good insight into the Excel VBA object model.

 

 

I did a little more tinkering to produce the following code:

'Set the print area for each worksheet.

'rngPrintArea1 is the named reference of a cell that contains a formula that generates an address. EX: ="A1:G"&12+Max(Sheet1!A:A) will generate A1:G14


Worksheets("Sheet1").PageSetup.PrintArea = Worksheets("Sheet1").Range("rngPrintArea1").Value

Worksheets("Sheet2").PageSetup.PrintArea = Worksheets("Sheet2").Range("rngPrintArea2").Value

Worksheets("Sheet3").PageSetup.PrintArea = Worksheets("Sheet3").Range("rngPrintArea3").Value


'Select the multiple sheets

Sheets(Array("Sheet1", "Sheet2 ", "Sheet3")).Select


‘Set filename

stFileName = ActiveWorkbook.Path & "\" & Worksheets("Sheet4").Range("A1").Value & " - report.pdf"


'Print all three to PDF

ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, Filename:= _

       stFileName _

    , Quality:=xlQualityStandard, IncludeDocProperties:=True, IgnorePrintAreas _

       :=False, OpenAfterPublish:=False


'Unselect the three worksheets, otherwise Excel will not allow you to change anything on the three worksheets

Sheets("Sheet1").Select

 

For more robust VBA code, check out MS Office Dev center’s entry on this topic.


Saturday, June 22, 2013

Is there a difference between managing and leading?

 

“Managers and leaders are often referred to synonymously, but only leaders allow their employees to solve problems with their own insight. The truth of the matter is this: Every leader may not be a manager, but every manager should be a leader.”

IIya Pozin

The above quote is from the article “The Difference Between Managers and Leaders” by IIya Pozin. The title caught my eye. As a manager myself, I once thought that being a manager made me a leader. I’ve learned through experience that

I like how IIya Pozin states the differences between leader and manager,

  1. Managers give answers, leaders ask questions.
  2. Managers criticize mistakes, leaders call attention to mistakes indirectly.
  3. Managers forget to praise, leaders reward even the smallest improvement.
  4. Managers focus on the bad, leaders emphasize the good.
  5. Managers want credit, leaders credit their teams.

As an analytics manager in the healthcare industry, the above statements make perfect sense. Analytics is discovery and communication of meaningful patterns in data (according to Wikipedia). I’ve found that analytics is more than reports and dashboards. You must use laser focus to discover the problem to analyze, build a coalition of colleagues to seek a resolution, and convey that resolution in a simple, compelling fashion.

Great analysts, managers or not, must aspire to be leaders in their organization.

Sunday, June 2, 2013

I just read “It’s Not about You”

 

“And the moment you begin thinking that it’s all about you, that you’re the deal, is the moment you begin losing your capacity to positively influence others’ lives. In a word, to lead. “

Bob Burg and John David Mann

I picked up the book, It’s not about You, at my local library. It’s a business leadership book the size of an iPad mini with only 127 pages. The authors, Bob Burg and John David Mann, present their case in the form of a parable. I was hesitant at first but was pleasantly surprised with this book.

The book’s description written on Amazon,

In this inspirational parable, we meet Ben, a young manager charged with persuading five hundred employees of a struggling chair manufacturer to agree to a merger as a way out of their financial woes. Facing what seems like an impossible uphill climb, Ben seeks the advice of Claire, an old friend, who introduces him to an eccentric elderly lady known simply as Aunt Elle.

Over the course of the week leading up to the crucial vote, Aunt Elle teaches Ben about the power of influence and positive persuasion. Ben also meets with each of the manufacturer's four top executives in an effort to sway them to his side, and instead comes away from each meeting with a different leadership lesson. But it's not until Ben reflects on his own experiences that he learns the critical principle so many people in positions of power fail to grasp: it's not about me, it's about you.

Ben learns the following 5 keys to leadership:

  • Key #1 Hold the vision
  • Key #2 Build your people
  • Key #3 Do the work
  • Key #4 Stand for something
  • Key #5 Share the mantle

Key #5 struck an accord with me. I took “Share the mantle” to mean, let others lead. Being the leader isn’t about being the center of attention. The book states that “the best way to increase your influence is to give it away”. This is a powerful concept when confronted with leading an organizational change. Employing new Business Intelligence tools takes leadership to overcome the pushback from letting go of the existing the technology.

Tuesday, August 14, 2012

PowerPivot’s Filter Context from a SQL perspective


The attempt to combine wisdom and power has only rarely been successful and then only for a short while.” Albert Einstein

I figure I best write down my thoughts before my new found wisdom escapes me. Every time I think I’ve finally understood “Filter Context”, it turns out that I really don’t get it. 

To be honest, I’ve read many definitions of “Filter Context” and descriptions about “Filter Context”. None of them have helped me to master the concept. I don’t come from the world of the multi-dimensional language MDX. Until recently, I didn’t see the usefulness of PivotTables when a solid SQL query can provide the same information.

Then, it came to me! What if I used the knowledge that I do have? Look at PivotTables and “Filter Context” through the perspective of SQL. Using this new perspective, I believe “Filter Context” is the following:

the key concept in PowerPivot allowing you to use Excel-like functions to dynamically alter the criteria of each cell in a PivotTable. Instead of relying on the PivotTable’s built-in process of creating a criteria based on the row value, column value, report filter, and/or slicer, utilize DAX functions to define the criteria. This new capability removes the PivotTable’s limited ability to solve business problems.

You can now move beyond the standard SUM and COUNT formulas, and create functions similar to those in SQL. “Filter Context” isn’t a feature like something you can select in an Excel ribbon or pop-up menu. It’s a behavior similar to Excel’s cell reference. Once you understand for example what the cell reference “A1:C3” is, you can use it in all sorts of Excel functions. Just like cell reference, “Filter Context” is fundamental to creating DAX formulas. 

I took my thoughts a little further. How does a PivotTable operate? It executes a SQL statement in each cell. Those SQL statements’ “where” clauses are automatically created based on the cell’s position in the PivotTable.

Let me start with a very basic data-set (call it data_table),
ID
Product
Color
amount
1
Pen
Red
2
3
Pencil
Blue
6
5
Pen
Blue
10
7
Pencil
Red
10

Create a standard PivotTable from the above data table,

I create the PivotTable below by:
·         Dragging Color into Row labels
·         Dragging Name into Column labels
·         Dragging amount into Values and leaving the “Summarize values as” SUM function
·         No Slicer or PivotTable’s report filter was used

 You get something like below,
Sum of amount
Column Labels
Row Labels
Pen
Pencil
Blue
10
6
Red
2
10

Not too useful!

If I apply my SQL analogy, the PivotTable really  looks like,
Column Label (Product)
Row Label (Color)
Pen
Pencil
Blue
select sum(amount)
from data_table
where Color = 'Blue' and Product = 'Pen'
select sum(amount)
from data_table
where Color = 'Blue' and Product = 'Pencil'
Red
select sum(amount)
from data_table
where Color = 'Red' and Product = 'Pen'
select sum(amount)
from data_table
where Color = 'Red' and Product = 'Pencil'

Each of the 4 cells in my PivotTable execute a query off of my data_table. In the cell that intersects Pen and Blue, SUM(amount) function will execute only for rows in the data_table where Color = 'Blue' and Product = 'Pen'.  No matter where I place this PivotTable in my worksheet or the entire workbook, this cell will always execute the SUM(amount) function where Color = 'Blue' and Product = 'Pen'.

What’s the big deal?
The standard PivotTable executes the SQL statements each time you refresh the table or alter the criteria of PivotTable. Basically, the PivotTable dynamically creates the “where” clause criteria based on the location of the SQL statement inside the PivotTable. The only way to alter this SQL statement is select a different aggregation function (COUNT, AVERAGE, and MAX). Not very flexible or useful for healthcare analytics!

In order to make a useful function, say a ratio of amount of Blue Pens to all Pens and Pencils, a PowerPivot function needs to be created. More appropriately, a DAX function needs to be created. PowerPivot allows you to create your own “where” clause statement, even join multiple tables, or utilize functions other than COUNT, AVERAGE, and MAX. This fact turns Excel’s PivotTable into a true Business Intelligence tool.

EXAMPLE DAX FORMULA #1 - Create a formula to compute Total Amount of all Pens and Pencils

In terms of SQL, I need to create a “where” clause that ignores both the row label and column label criteria for each cell of the PivotTable. That would look like,

Column Label (Product)
Row Label (Color)
Pen
Pencil
Blue
select sum(amount)
from data_table
where (ignore Color = 'Blue' and ignore Product = 'Pen')
select sum(amount)
from data_table
where (ignore Color = 'Blue' and ignore Product = 'Pencil')
Red
select sum(amount)
from data_table
where (ignore Color = 'Red' and ignore Product = 'Pen')
select sum(amount)
from data_table
where (ignore Color = 'Red' and ignore Product = 'Pencil')

That is, I want my PivotTable to ignore the built-in “where” clause of “where Color = 'Blue' and Product = 'Pen'” and utilize a “where” clause of my creation. I want the total of all Pens and Pencils to appear in each cell of my PivotTable.

To ignore the PivotTable’s built-in where clause statement, I created the following DAX formula,

TotalAmount=CALCULATE(sum(data_table[amount]),all(data_table))

This is analogous to writing,
SELECT sum(data_table[amount])
FROM data_table

I want to compute the total amount regardless of where this function is placed in the PivotTable. I don’t care if the end user slices the PivotTable by Red and dices the PivotTable by Pen resulting in only one cell in the PivotTable, I want to override the PivotTable’s built-in criteria. The SQL statement is a simple one, sum all values in the column [amount] in the table data_table.

Let’s look at the DAX formula (called a measure in PowerPivot terminology) again,

TotalAmount=CALCULATE(sum(data_table[amount]),all(data_table))

DAX function breakdown
·         TotalAmount – name of the measure
                The formula that changes the criteria (changes the “filter context”). In my example, CALCULATE sums all the amounts in the table regardless of its position in the PivotTable or criteria selected by the user.
o   <expression> -
§  sum(data_table[amount]) – simple formula to sum the amounts in the data_table
o   <filter1> -
§  all(data_table) – return all the rows in data_table regardless of the cell this formula is located.

In the PowerPivot’s Field list, right click on the table and select new measure. Excel exposes the dialog box below for you to enter your DAX function,
clip_image001


By selecting the TotalAmount measure only, the PivotTable looks like,

TotalAmount
Column Labels
Row Labels
Pen
Pencil
Blue
28
28
Red
28
28

If I include the sum of amounts and TotalAmount measures, the PowerPivot table looks like,

Column Labels
Pen
Pencil
Row Labels
Sum of amount
TotalAmount
Sum of amount
TotalAmount
Blue
10
28
6
28
Red
2
28
10
28


EXAMPLE DAX FORMULA #2 - rank the 4 items in the data table by amount

I want to rank the each row of data_table by each row’s amount. In SQL, I would write (using T-SQL):

SELECT ID, amount, RANK() OVER (ORDER BY amount) as Rank
FROM data_table

Leave it to Microsoft to provide multiple ways to calculate rank in DAX. I’m choosing to review a longer version for demonstration purposes (PowerPivot version 2 has a built-in RANK function),

Rank=COUNTROWS
(
                FILTER(
                                ALL(data_table[ID]),
                                data_table[SumAmount] >
                                                CALCULATE(data_table[SumAmount],values(data_table[id]))
                                )
) + 1

DAX function breakdown
·         COUNTROWS(<table>) – Count the number of rows in the table defined by formulas defined inside the parenthesis
·         FILTER(<table>,<filter>)  - Returns a table to the COUNTROWS function that only contains rows that have amounts greater than the row that this function is located.
o   First, ignore the row and column criteria in each cell
o   Then compute the ranking algorithm,
data_table[SumAmount] > CALCULATE(data_table[SumAmount],VALUES(data_table[id]))
§  For each row, evaluate whether the current’s rows amount is greater than selected  row
§  In order for this formula to work, the measure, data_table[SumAmount] , must be utilized.
·         SumAmount =sum(data_table[amount])

Again, a view of the dialog box for entering the DAX functionclip_image002

The resulting PivotTable looks like,
ID
SumAmount
Rank
1
2
4
3
6
3
5
10
2
7
12
1

PowerPivot allows you to alter the standard PivotTable by:
·         Creating powerful, dynamic functions
·         Create useful formulas such as pmpm, per 1000, percent compliance

There is a lot of nuance in “Filter Context” that I didn’t describe. I wanted to share my new understanding of the key PowerPivot concept. Key items to remember:
·         When a measure is placed in a PivotTable, it’s execution in each cell depends on the intersection of row, column, report filter, and slicers. In essence, PowerPivot allows you to change this intersection by using DAX functions
·         Think of “Filter Context” as changing the ”where” clause statement in a SQL statement.
·         PowerPivot allows for the creation of useful functions inside PivotTables, similar to functions in a standard Excel worksheet. Percent compliance rates, per member per month, and encounters per 1000 are a few of the metrics that can now be calculated on the fly inside an Excel PivotTable.