How to use Excel Data Model & Relationships

Share

Facebook
Twitter
LinkedIn

Have you ever been in a VLOOKUP hell?

Its what happens when you have to write a lot of vlookup formulas before you can start analyzing your data. Every day, millions of analysts and managers enter VLOOKUP hell and suffer. They connect table 1 with table 2 so that all the data needed for making that pivot report is on one place. If you are one of those, then you are going to love Excel’s data model & relationships feature.

Table relationships & Data model feature of Excel - cartoon

In simple words, this feature helps you connect one set of data with another set of data so that you can create combined pivot reports.

Practical Example – V(X)LOOKUP hell vs. Data Model heaven

Lets say you are looking sales data for your company. You have transaction data like below.

Example data

And you want to find out how many units you are selling by product category and customer’s gender.

Unfortunately, you only have product ID & customer ID.

With VLOOKUP Hell,

  1. You first fetch all the customer and product data and place them in separate ranges.
  2. Then write a vlookup formula to fetch product category, another to fetch customer gender.
  3. Then fill down the formulas for entire list of transactions.
  4. Now make a pivot table.

Assuming you have 30,000 transactions, you have to write 60,000 VLOOKUP formulas to create this one report!!!

With Data Model heaven,

  1. Create relationships between Sales, Products & Customer tables
  2. Create a pivot table

Creating a relationship in Excel – Step by Step tutorial

  1. Relationship feature in Excel 2013 data ribbon tab
    First set up your data as tables. To create a table, select any cell in range and press CTRL+T. Specify a name for your table from design tab. Read introduction to Excel tables to understand more.
  2. Now, go to data ribbon & click on relationships button.
  3. Click New to create a new relationship.
  4. Select Source table & column name. Map it to target table & column name. It does not matter which order you use here. Excel is smart enough to adjust the relationship.
    Creating a new relationship in Excel 2013 - how to?
  5. Add more relationships as needed.

Using relationships in Pivot reports & analysis

  1. Select any table and insert a pivot table (Insert > Pivot table, more on Pivot tables).
  2. Make sure you check the “Add this data to data model” check box.
    Adding a pivot table with data model in Excel 2013
  3. In your pivot table field list, check “ALL” instead of “ACTIVE” to see all table names.
  4. Select fields from various tables to create a combined pivot report or pivot chart

Example: Category & Gender Sales Report

  1. Add category to row labels
  2. Add gender to column labels
  3. Add quantity to values
  4. and your report is ready!
Example Pivot report made with Excel data model

Things to keep in mind when you using relationships

  • Same data types in both columns: Columns that you are connecting in both tables should have same data type (ie both numbers or dates or text etc.)
  • One to one or One to many relationships only: Excel 2013 supports only one to many or one to one relationships. That means one of the tables must have no duplicate values on the column you are linking to. (for example products table should not have duplicate product IDs).
  • You can add slicers too: You can slice these pivot tables on any field you want (just like normal pivot tables). For example, you can further slice the above report on customer’s profession or product’s SKU size.

Benefits of Data Model based Pivot Tables

Once you have a data model in spreadsheet, you will enjoy several benefits (apart from multi-table pivots that is). They are,

  • Distinct counts: This simple but often tricky to calculate number is easy to get once you have data model based pivot. Just go to value field settings and change the summary type to “Distinct count”. Here is a tip explaining how to get distinct counts in Excel pivots.
  • Measures & DAX: Once you have a Data Model, you can unleash the full Power Pivot features on your workbook. You can create measures (using DAX language) and calculate things that are otherwise impossible with regular Excel. Here is an example of percentage of something calculation with DAX & Data Model, to get started.
  • Pivots from data in other files & databases: You can combine data model with the abilities of Power Query to create pivots from data in other places. For example, you can make a pivot from sales data in SAP with customer data in CRM system. Here is an overview of what is Power Query?
  • Pivots from more than 1mn rows of data: You can connect to very large datasets and make pivots from them with the help of data model. Here is a demo of how to set up data model for 1+mn rows of data.
  • Convert Pivot Tables to formulas: Once you have a data model based pivot table, you can turn it in to a set of formulas. You can access this feature from “Analyze” ribbon. This will replace your pivot with a bunch of CUBE formulas. Here is an overview of CUBE formulas.

Drawbacks of Data Model:

Of course, its not all cup cakes and coffee with Data Model. There are a few drawbacks of data model based pivot tables.

  • Compatibility: Data model & relationship feature is available only in Excel 2013 or above. This means, you cannot create or share such pivot reports with people using older versions of Excel.
  • Not able to group data: In regular Pivot Tables, you can group numeric, data or text fields. But with data model pivot tables, you can no longer group data. You must create another table with the group mapping and use it as a relationship.

Download Example File

Click here to download Excel data model demo file. It contains 3 different tables and a combined pivot report (with slicer) to show you what is possible.

Do you use relationships?

Ever since discovering PowerPivot, I kind of stopped using VLOOKUP (or XLOOKUP) for most of my own analysis. Now that relationships are part of main Excel functionality, I am using them even more.

What about you? Are you using relationships & data model in Excel? What cool things are you doing with it? Share your tips with us using comments.

Want even more? Try PowerPivot

If you want even more out of your reports, then try PowerPivot. It is a new feature in Excel 2013 (available as add-in in Excel 2010) that can let you do lots of powerful analysis on massive amounts of data. Here is an introduction to PowerPivot.

Facebook
Twitter
LinkedIn

Share this tip with your colleagues

Excel and Power BI tips - Chandoo.org Newsletter

Get FREE Excel + Power BI Tips

Simple, fun and useful emails, once per week.

Learn & be awesome.

Welcome to Chandoo.org

Thank you so much for visiting. My aim is to make you awesome in Excel & Power BI. I do this by sharing videos, tips, examples and downloads on this website. There are more than 1,000 pages with all things Excel, Power BI, Dashboards & VBA here. Go ahead and spend few minutes to be AWESOME.

Read my storyFREE Excel tips book

Overall I learned a lot and I thought you did a great job of explaining how to do things. This will definitely elevate my reporting in the future.
Rebekah S
Reporting Analyst
Excel formula list - 100+ examples and howto guide for you

From simple to complex, there is a formula for every occasion. Check out the list now.

Calendars, invoices, trackers and much more. All free, fun and fantastic.

Advanced Pivot Table tricks

Power Query, Data model, DAX, Filters, Slicers, Conditional formats and beautiful charts. It's all here.

Still on fence about Power BI? In this getting started guide, learn what is Power BI, how to get it and how to create your first report from scratch.

25 Responses to “Display Alerts in Dashboards to Grab User Attention [Quick Tip]”

  1. Alex Kerin says:

    I prefer the red,grey,light grey,black icon set. I've also used in-cell pie charts from Fabrice's Sparklines for Excel as an alert which could also provide another piece of information.

  2. Alex Kerin says:

    I prefer the red,grey,light grey,black icon set. I've also used in-cell pie charts from Fabrice's Sparklines for Excel as an alert which can also provide another piece of information.

    For Excel 2007, your formula should do the same as the Excel 2003 version, so that non-alert rows are blank - if they are 0, the unnecessary green icon will show

  3. Rohit1409 says:

    Hi Chandoo,

    Nice Post !! just to add something for EXL 2003, we can also 4 Ifs and link to the alert data

    For Ex: If we have alert data in Cell A2 and want to split in 4 orders namely <25%, 25-50%, 50-75% and 75%< then we can following formula and put fonts as you have suggested :

    =IF(A2<0.25,CHAR(153),IF(A2<=0.5,CHAR(155),IF(A2=0.76,CHAR(152)))))

    And then using Conditional Formating we can dashboard reflected on different COLOURS as per their respective alert.

    Best Regards
    Rohit1409

  4. Rohit1409 says:

    Hi Chandoo,

    Nice Post !!! just to add something for EXL 2003, we can also 4 Ifs and link to the alert data

    For Ex: If we have alert data in Cell A2 and want to split in 4 orders namely <25%, 25-50%, 50-75% and 75%< then we can following formula and put fonts as you have suggested :

    =IF(A2<0.25,CHAR(153),IF(A2<=0.5,CHAR(155),IF(A2=0.76,CHAR(152)))))

    And then using Conditional Formating we can dashboard reflected on different COLOURS as per their respective alert.

    Best Regards
    Rohit1409

  5. Rohit1409 says:

    The Complete formula [Don't Know how it got cut ]

    =IF(A2<0.25,CHAR(153),IF(A2<=0.5,CHAR(155),IF(A2=0.76,CHAR(152)))))

    PS : Use in single line [I have split it to avoid cuts 😉 ]

  6. Rohit1409 says:

    Hi Chandoo..

    why it is not displaying the complete formula..

    anyways here is the balance

    "=IF(A2<0.25,CHAR(153), IF(A2<=0.5,CHAR(155), IF(A2=0.76,CHAR(152)))))"

  7. Chandoo says:

    @Rohit... your formulas are fine. Just that the width of comment area is fixed and hence my website is cropping it at 640pixels. I just edited your formula and added few white spaces so that it wraps nicely.

    Very good idea btw.. kudos!

  8. Tom says:

    Hi,
    Maybe just go for 'bold' ; 'underline' or 'italic' to draw the users attention? Those methods (if those can be called methods) are used cross media type (books, journals, blogs, billboards, ...) to guide the readers eye to valuable information.
    Just a basic thought

  9. Chandoo says:

    @Tom.. good idea..

  10. [...] has a very nice writeup on how to add such alerts to dashboard sheets. Possibly related posts: (automatically generated)Divide your data set into workbooksHow to enforce [...]

  11. Ramesh Panakkal says:

    Hi Chandoo,

    You certainly grabbed my attention! although I wasn't sure what my brother (Suresh) and cousin (Shyam) were doing right, and I was doing wrong? 😉

    I love your blog btw - Many thanks for all your hard work in unravelling the secrets and mysteries of Excel!

    Best regards
    Ramesh

  12. Jeff Whitesel says:

    I thought I saw an advertisment for a book about learning excel called excel himalaya or something. It cost about 35.00 us money but seemed to have the things I need to have my admin assistant to start to use. I was hoping to start with this book and then send her to school if she shows some interest and aptitude. Any help on this would be appreciated. Thanks

    Great web site and information!!!!

  13. [...] There are lots of numbers in this dashboard. I would suggest adding few more visualizations like showing indicators or applying conditional formatting or replacing a table with a chart. This would reduce the [...]

  14. [...] is the same technique as alert icons in dashboard. Just that I also showed green [...]

  15. [...] is the same technique as alert icons in dashboard. Just that I also showed green [...]

  16. RROBBITT says:

    Hi Chandoo
    Firstly thanks for all the cool tips on how to use Excel better.

    I am new to the site and have a question which you may be able to assist with but dont know if these comment boxes are the best way of asking ?

    I am looking at assets and trying to calculate the depreciation total by taking a year (say 2010) adding the expected life of the asset (say 10 years) then comparing that to a future date (say 2015) using an IF statement. The calculation in normal is - IF((year in col B (2010) plus 10years)>year 2015, add a years depreciation, otherwise leave blank). The converted date value does not appear able to add 10 years in order to compare it to 2015. Am I missing something ?

  17. Rocky says:

    I use the “IF” Statement in conjunction with Conditional Formatting in MS Excel to give verbiage to alert one of a required action, dependant on a review date. This makes a visual stimulus, plus it clues one as to what the conditional format is trying to warn you about and what follow-up actions are required.

  18. Wow, I'm really impressed with dashboards. I had no idea this stuff was even possible with excel. I'd like to offer an interactive dashboard to my customers, showing analytics of their data. I have a .pdf file with the datapoints. I'd like them to enter the data on my website, and be able to see their data. Is something like that possible.

  19. Adam G says:

    Hi Chandoo,

    I've recently purchased the package for both templates.

    In the portfolio dashboard,under the calculations worksheet, I'm attempting to change the date range in the gantt chart to show only the range of the project that starts in late 2013.  How do I do this?

    Thanks
    Adam 

  20. [...] is the same technique as alert icons in dashboard. Just that I also showed green [...]

  21. Bianca says:

    Hi Chandoo,
    I'm new at Excel Dashboard and found your blog really useful and helpful! It's very nice of you that you dedicate your time to do this.
    Could you please explain how can I use Alerts based on dates on a Dashboar?
    For example, if a target date is coming closer to the actual date, the alert is yellow or red.
    I'd really appreciate some help!
    Thank you

  22. Marco says:

    Where can I download the file Excel of Averall Statistics ???
    Thanks a lot.

Leave a Reply