How to Use Sparklines in Excel to Visualise Data Trends

Sparklines are a powerful tool in Excel that allow you to visualise data trends in a condensed chart format. Unlike normal Excel charts, Sparklines are embedded in a single cell, making them ideal for displaying trends in sales figures, website hits, and other data over a period of time.

In this blog post, we’ll show you how to create and customise Sparklines in Excel, and provide some examples of how they can be used in different business roles and industries.

For instance, sales managers can use Sparklines to track sales figures over time, while marketing professionals can use them to monitor website traffic. Sparklines can also be used in finance to track stock prices or in healthcare to monitor patient vitals.

There are 3 types of Sparkline available, “line”, “column” and “Win/Loss”:

How to Use Sparklines in Excel to Visualise Data Trends

In the following example we see how a sales manager can quickly create Sparklines to easily analyse and compare performance across multiple sales regions.

Creating a Sparkline

Unlike a normal Excel chart that ‘floats’ on top of the spreadsheet, a Sparkline is embedded in a single cell. Create a Sparkline for Region A figures Jan-Oct as follows:

  1. Select a cell to the right of the data you want to visualise – see below:

How to Use Sparklines in Excel to Visualise Data Trends

2. Go to INSERT > SPARKLINES > LINE

3. In the ‘Data Range’ field, select all the cells containing numbers to the left of the selected cell. Click OK to display the following Sparkline

How to Use Sparklines in Excel to Visualise Data Trends

Editing a Sparkline

  1. To see each point of the Sparkline more clearly, go to SPARKLINE > SHOW > HIGH POINT.

Note the same values of 28 for both March and July give rise to 2 red markers on the Sparkline.

How to Use Sparklines in Excel to Visualise Data Trends

Reducing the July figure to 26 would result in just one marker for March – see below:

How to Use Sparklines in Excel to Visualise Data Trends

2. Reducing the July figure to 26 would result in just one marker for March – see below:

How to Use Sparklines in Excel to Visualise Data Trends

3. Now change the August figure to -5 and then change the type to WIN/LOSS

4. Untick ‘High Point’ and tick ‘Negative Point’

5. Select a different Sparkline style to reflect RAG status colours (Red, Amber, Green) i.e. Red (negative values) and Green (positive values)

Note the main purpose of the WIN/LOSS Sparkline is to show which values are positive or negative – see below.

How to Use Sparklines in Excel to Visualise Data Trends

6. Change the type back to the default ‘Sparkline’ and set the following:

a. Tick ‘High point’ and ‘Low point’

b. Untick ‘Negative points’

c. Sparkline colour to blue.

Copying a Sparkline

Once you have created a Sparkline, all its attributes can be copied down to represent other rows of data:

How to Use Sparklines in Excel to Visualise Data Trends

The result is shown below:

How to Use Sparklines in Excel to Visualise Data Trends

2. To edit the Sparklines, select any one within a single cell, do the edits and all of them will be changed as a group

3. If you want to change one specific Sparkline without affecting the others, go to SPARKLINE > GROUP > UNGROUP

Deleting Sparklines

Unlike for normal charts and data generally, the delete button will not work for deleting Sparklines.

Select the Sparklines and go to SPARKLINES > GROUP > CLEAR > CLEAR SELECTED SPARKLINES

Conclusion

In conclusion, Sparklines are a great way to visualise data trends in Excel, and can be used in a variety of business roles and industries. By following the steps outlined in this blog post, you can create and customise Sparklines to better understand your data and make more informed decisions.

Power BI – Advanced options to make forecasting models

Finally, there are new advanced options to create forecasting models in Power BI. Microsoft introduced the LINEST function and LINESTX function in the Power BI desktop February 2023 version.

function

The LINEST function in Excel has always been an important tool for perform linear regression, leveraging the Least Squares method, to calculate a straight line that best fits the given data. The functions are especially useful in predicting unknown values (Y) given known values (X) and can work with any number of X columns.

In this blog post, we will use the LINEST function as our example. The LINEST function creates a table with a single row explaining the line and additional statistics. The table includes the columns slopes, intercepts, standard errors, and the coefficient of determination.

All the information needed for the equation of the fitted line can be constructed: Y = Slope1 * X1 + Slope2 * X2 + …+ Intercept.

In this example the data set is sales data. It include total monthly sales, how many sales reps, monthly marketing expenses, and monthly number of sales calls.

The Power BI report should visualise how future changes in number of sales reps, sales calls, and marketing budget will affect the future sales.

Funciton

The LINEST function

Syntax

LINEST ( <columnY>, <columnX>[, …], [<const>] )

Parameters

To create the LINEST table click New Table on the Modelling tab. In this example, we will use three X values.

Linest result = LINEST(‘sales stats'[Sales],’sales stats'[Marketing Expenses],’sales stats'[sales calls],’sales stats'[Sales reps])

 

This DAX return a single row table including a lot of statistics, but in this blog post, you will only see how the y-intercept and sloop is used for predictions.

The linear regression equation:

Y = Slope1 * X1 + Slope2 * X2 + …+ Intercept.

The DAX will look like this in this model:

Predictions = sum(‘Linest result'[Intercept])+SUM(‘Linest result'[Slope1])*SUM(‘sales stats'[Marketing Expenses])+sum(‘Linest result'[Slope2])*sum(‘sales stats'[sales calls])+SUM(‘Linest result'[Slope3])*SUM(‘sales stats'[Sales reps])

 

The DAX measure is added to the matrix to give an indication of the accuracy.

To give the audience an option to predict how changes will affect the sales, parameter tables can be used. Click New parameter on the Modelling tab, add the parameters, and click OK.

Function

The New Parameter tool creates a table with the parameter values and a slicer. Therefore, the audience can select the parameters.

Next step will be to write the DAX to show the prediction based on selected parameters.

Again, the linear regression equation:

Y = Slope1 * X1 + Slope2 * X2 + …+ Intercept.

The sloop values and the intercept are in the Prediction table the LINEST function created earlier in this blog post and the X values will come from the three parameter slicers.

The DAX will in this example look like this:

Predictions based on parameters = sum(‘Linest result'[Intercept])+SELECTEDVALUE(‘Marketing Budget'[Marketing Budget])*SUM(‘Linest result'[Slope1])+SELECTEDVALUE(‘Number of sales calls'[Number of sales calls])*sum(‘Linest result'[Slope2])+SELECTEDVALUE(‘Number of Sales reps'[Number of Sales reps])*sum(‘Linest result'[Slope3])

 

We can use the SELECTEDVALUE function to return the selected values from the slicers.

 

The measure is here added to a Card visual to visualise the result.

Function

In a forecast model like this it could be useful to investigate how much or if the X values (marketing budget, number of  sales calls, and number of sales reps) affect the sales.

You can find a particularly useful Quick Measure, which can tell you this, the Correlation Coefficient quick measure.

You will here see how the correlation is calculated between the Sales and Marketing Budget.

The DAX will look like this, but you will not need to write it yourself.

Sales and Marketing Expenses correlation for Month =

VAR __CORRELATION_TABLE = VALUES(‘sales stats'[Month])

VAR __COUNT =

COUNTX(

KEEPFILTERS(__CORRELATION_TABLE),

CALCULATE(

SUM(‘sales stats'[Sales])

* SUM(‘sales stats'[Marketing Expenses])

)

)

VAR __SUM_X =

SUMX(

KEEPFILTERS(__CORRELATION_TABLE),

CALCULATE(SUM(‘sales stats'[Sales]))

)

VAR __SUM_Y =

SUMX(

KEEPFILTERS(__CORRELATION_TABLE),

CALCULATE(SUM(‘sales stats'[Marketing Expenses]))

)

VAR __SUM_XY =

SUMX(

KEEPFILTERS(__CORRELATION_TABLE),

CALCULATE(

SUM(‘sales stats'[Sales])

* SUM(‘sales stats'[Marketing Expenses]) * 1.

)

)

VAR __SUM_X2 =

SUMX(

KEEPFILTERS(__CORRELATION_TABLE),

CALCULATE(SUM(‘sales stats'[Sales]) ^ 2)

)

VAR __SUM_Y2 =

SUMX(

KEEPFILTERS(__CORRELATION_TABLE),

CALCULATE(SUM(‘sales stats'[Marketing Expenses]) ^ 2)

)

RETURN

DIVIDE(

__COUNT * __SUM_XY – __SUM_X * __SUM_Y * 1.,

SQRT(

(__COUNT * __SUM_X2 – __SUM_X ^ 2)

* (__COUNT * __SUM_Y2 – __SUM_Y ^ 2)

)

)

 

You just need to click Quick Measure on the Home tab and then add the parameters from your tables. In this example it will look like this, Power BI desktop will write the DAX:

Function

You will see here that this Correlation Coefficient measure returns 0.28. This means that we have a positive correlation. That is to say our sales have improved when we have spent more money on marketing. However, the number is disappointing. There is an almost non-existent relationship between Sales and the Marketing budget . It is suggested here that when your company spends more money on Marketing, the sales increase comparatively poorly.

The correlation between Sales and Number of Sales calls, and the Correlation between Sales and  Number of Sales reps are also calculated in this model and these results are much more satisfying.

Based on the correlation between the X values I would remove the Marketing Budget from my Prediction measures to get a more accurate result, or I would find a better way of using the budget.

We can visualise correlation measures  on Scatter charts, and it is obverse that the relationship between Sales and calls are much closer than the relationship between Sales and Marketing Expenses.

Function

I will end this blog post by also create a dynamic text DAX measure to describe the prediction displayed in the card. This text DAX text result will appear in a text box.

The DAX

Explain the prediction = “The card above shows sales predictions based on a marketing budget of ” & SELECTEDVALUE(‘Marketing Budget'[Marketing Budget]) & “, ” & SELECTEDVALUE(‘Number of sales calls'[Number of sales calls]) &  ” number of sales calls, and ” & SELECTEDVALUE(‘Number of Sales reps'[Number of Sales reps]) & ” sales reps.”

 

By adding this DAX to the title of a Text box, you will create a dynamic Text box, which will show selected values from the slicers.

You can find the dynamic Text box to the right just under the Card with the prediction. The text box will display the values you can see, and you can select them from the slicers.

Function

Conclusion

I have missed some more advanced data analysis tools in Power BI desktop. I really appreciate that we now getting more options. It was possible to calculate the slope and intercept before we got the LINEST function, but it was a nightmare. I did ones calculate the slope, but the DAX  was a endless number of DAX and very time consuming. Well done Microsoft and please keep on the good work.