implementing histograms in excel 2

16
Implementing histograms in Excel 2013 using DAX query tables and PowerPivot I got a great question last month on how to implement a histogram in PowerPivot, similar to this great blog post by Tomislav Piasevoli for Multi Dimensional. I decided to solve the problem in Excel 2013, PowerPivot and DAX and show you some of the great things Excel 2013 allows us to do. First thing I did was import the data into Excel. As you might know you no longer need to separately install PowerPivot. Excel 2013 now by default contains our Tabular engine and the PowerPivot add-in when you install Excel. When you import data from sources to Excel they will be available in our Tabular engine. I start by opening Excel 2013, go to the data tab and import from SQL Server: I select the database I want to import from (same source as Tomislavs: Adventureworks) and select the tables I am interested in: Page 1 of 16 Kasper de Jonge PowerPivot Blog | Implementing histograms in Excel 2013 using DAX q... 5/13/2014 http://www.powerpivotblog.nl/implementing-histograms-in-excel-2013-using-dax-query-ta...

Upload: cancelthis0035994

Post on 19-Jan-2016

40 views

Category:

Documents


0 download

DESCRIPTION

.

TRANSCRIPT

Page 1: Implementing Histograms in Excel 2

Implementing histograms in Excel 2013 using DAX query tables and PowerPivotI got a great question last month on how to implement a histogram in PowerPivot, similar to this great blog post by Tomislav Piasevoli for Multi Dimensional. I decided to solve the problem in Excel 2013, PowerPivot and DAX and show you some of the great things Excel 2013 allows us to do.

First thing I did was import the data into Excel. As you might know you no longer need to separately install PowerPivot. Excel 2013 now by default contains our Tabular engine and the PowerPivot add-in when you install Excel. When you import data from sources to Excel they will be available in our Tabular engine.

I start by opening Excel 2013, go to the data tab and import from SQL Server:

I select the database I want to import from (same source as Tomislavs: Adventureworks) and select the tables I am interested in:

Page 1 of 16Kasper de Jonge PowerPivot Blog | Implementing histograms in Excel 2013 using DAX q...

5/13/2014http://www.powerpivotblog.nl/implementing-histograms-in-excel-2013-using-dax-query-ta...

Page 2: Implementing Histograms in Excel 2

Key here is to select the checkbox “Enable selection of multiple tables”. As soon as you select that the tables are imported into the Tabular engine. Press Finish and the importing starts.

When the import is completed you can select what you want to do with the data, I selected pivottable:

Page 2 of 16Kasper de Jonge PowerPivot Blog | Implementing histograms in Excel 2013 using DAX q...

5/13/2014http://www.powerpivotblog.nl/implementing-histograms-in-excel-2013-using-dax-query-ta...

Page 3: Implementing Histograms in Excel 2

Now I get the pivotable:

Page 3 of 16Kasper de Jonge PowerPivot Blog | Implementing histograms in Excel 2013 using DAX q...

5/13/2014http://www.powerpivotblog.nl/implementing-histograms-in-excel-2013-using-dax-query-ta...

Page 4: Implementing Histograms in Excel 2

Ok now here starts the fun part . We now have two tables, one with all the resellers and all their sales. What we want to do now is know what the sales count of the resellers and have that available to pivot on. But in order for us to get this available to us we need to add this data to the model.

And this is where some new awesome features of Excel 2013 come into play. First I need to create a measure that counts the number of orders. For this I need the PowerPivot add-in. Make sure that you have this enabled, click on File, Options, Select Add-ins and Manage Com Add-ins. Press Go.

Page 4 of 16Kasper de Jonge PowerPivot Blog | Implementing histograms in Excel 2013 using DAX q...

5/13/2014http://www.powerpivotblog.nl/implementing-histograms-in-excel-2013-using-dax-query-ta...

Page 5: Implementing Histograms in Excel 2

Now select PowerPivot and press ok:

Now notice that the PowerPivot tab is available in the ribbon, and click on Manage, to manage the model

Page 5 of 16Kasper de Jonge PowerPivot Blog | Implementing histograms in Excel 2013 using DAX q...

5/13/2014http://www.powerpivotblog.nl/implementing-histograms-in-excel-2013-using-dax-query-ta...

Page 6: Implementing Histograms in Excel 2

This will open the PowerPivot window, now select the FactResellerSales table and create a new measure:

NRofOrders:=COUNTROWS(values(FactResellerSales[SalesOrderNumber]))+0

This will give us the Nr of orders based on the salesordernumber, observe the +0 to make sure it returns 0 when no rows are returned.

Now to make use of this measure I am going to create a new table based on a DAX query, this is a hidden feature in Excel 2013 but very very useful! Lets go back to Excel, select the data tab, click on Existing connections and select Tables:

Page 6 of 16Kasper de Jonge PowerPivot Blog | Implementing histograms in Excel 2013 using DAX q...

5/13/2014http://www.powerpivotblog.nl/implementing-histograms-in-excel-2013-using-dax-query-ta...

Page 7: Implementing Histograms in Excel 2

Select either one of them, doesn’t really matter. Import the data as a table on a new sheet:

This will create a Excel table based on the data in our model:

Page 7 of 16Kasper de Jonge PowerPivot Blog | Implementing histograms in Excel 2013 using DAX q...

5/13/2014http://www.powerpivotblog.nl/implementing-histograms-in-excel-2013-using-dax-query-ta...

Page 8: Implementing Histograms in Excel 2

Now this is where the fun starts, right mouse click on the table, click Table, Edit DAX (yes !)

Page 8 of 16Kasper de Jonge PowerPivot Blog | Implementing histograms in Excel 2013 using DAX q...

5/13/2014http://www.powerpivotblog.nl/implementing-histograms-in-excel-2013-using-dax-query-ta...

Page 9: Implementing Histograms in Excel 2

Now a very limited dialog will be shown that has no syntax checking or formula help at all. But still an awesome feature for anyone who knows DAX. What this allows us to do is create a Excel table based on a DAX expression.

Now change the command type from Table to DAX and off you go:

Page 9 of 16Kasper de Jonge PowerPivot Blog | Implementing histograms in Excel 2013 using DAX q...

5/13/2014http://www.powerpivotblog.nl/implementing-histograms-in-excel-2013-using-dax-query-ta...

Page 10: Implementing Histograms in Excel 2

In my case I created the following DAX Query:

evaluatefilter(summarize(DimReseller,  DimReseller[ResellerKey], “nr orders”, FactResellerSales[NRofOrders]), FactResellerSales[NRofOrders] >= 0)order by  FactResellerSales[NRofOrders]

This query gives me all resellers with the number of orders where they have 0 or more sales.

Page 10 of 16Kasper de Jonge PowerPivot Blog | Implementing histograms in Excel 2013 using DA...

5/13/2014http://www.powerpivotblog.nl/implementing-histograms-in-excel-2013-using-dax-query-ta...

Page 11: Implementing Histograms in Excel 2

I also made sure the table name was changes to “OrdersByReseller”. So how cool is that.. now we have a table in Excel that is based on a DAX query! One thing to note here is the change in behavior of Refresh inside Excel. Refresh in Excel will now automatically refresh the data as well, it will reach back to the underlying datasource and  add the data to the model. You should no longer need to press refresh to get the data of Excel to be in sync with the model. When you refresh the result of your DAX query will also be updated.

Ok, now we have this table but now we still don’t have a column with the number of orders that we can use as histogram. Well this is now really simple, we will push this table back to the model. Select the table, click on the PowerPivot tab and click Add to model. This will push the table back to the model:

Page 11 of 16Kasper de Jonge PowerPivot Blog | Implementing histograms in Excel 2013 using DA...

5/13/2014http://www.powerpivotblog.nl/implementing-histograms-in-excel-2013-using-dax-query-ta...

Page 12: Implementing Histograms in Excel 2

And again this table will automatically be update as soon as new data comes in from the source.

Now I can create a pivottable to put nr orders as a Row:

Page 12 of 16Kasper de Jonge PowerPivot Blog | Implementing histograms in Excel 2013 using DA...

5/13/2014http://www.powerpivotblog.nl/implementing-histograms-in-excel-2013-using-dax-query-ta...

Page 13: Implementing Histograms in Excel 2

Now in order to get the Reseller Orders Frequency I create three measures:

Reseller Orders Frequency:=COUNTA([ResellerKey])All orders:=CALCULATE([Reseller Orders Frequency], ALL(OrdersByReseller))Reseller Orders Frequency %:=[Reseller Orders Frequency]/[All orders]

I have hidden All order so it wouldn’t show up in the pivottable and set format to % on the “Reseller Orders Frequency %” measure.

And here we have it:

Page 13 of 16Kasper de Jonge PowerPivot Blog | Implementing histograms in Excel 2013 using DA...

5/13/2014http://www.powerpivotblog.nl/implementing-histograms-in-excel-2013-using-dax-query-ta...

Page 14: Implementing Histograms in Excel 2

Pretty awesome right ? Just go back to the blog post from 2009 from Tomislav and compare all the work we needed to do there compared to this. This will open up so many new scenarios !

Have fun exploring Excel 2013 and PowerPivot.

Posted on July 24, 2012 by Kasper de Jonge in Uncategorized

18 Responses to Implementing histograms in Excel 2013 using DAX query tables and PowerPivot

Really nice post and features provided in Excel 2013 Kasper!

Page 14 of 16Kasper de Jonge PowerPivot Blog | Implementing histograms in Excel 2013 using DA...

5/13/2014http://www.powerpivotblog.nl/implementing-histograms-in-excel-2013-using-dax-query-ta...

Page 15: Implementing Histograms in Excel 2

Thanks for the mention btw.

from Tomislav Piasevoli July 24, 2012 at 1:29 pm

Nicebut you can do it also in excel 2010

from Dan July 24, 2012 at 9:03 pm

Hi Dan,

No this is a native Excel feature that is new in Excel 2013 so you cannot do it in Excel 2010.

Kasper

from Kasper de Jonge July 25, 2012 at 9:07 am

What is the maximum number of number of rows that Excel 2013 supports?

Thanks.

from Steve G. August 2, 2012 at 9:02 pm

HI Steve,

If you use the Data model you can add as much rows as fit in your memory.

Thanks,Kasper

from Kasper de Jonge January 11, 2013 at 10:03 am

Wouldn’t you be able to do something similar with the PowerPivot add-in installed in an Office 2010 suite?

from alex narayan August 27, 2012 at 2:41 pm

@Kasper de Jonge Right-click on table cell, then select Table | Edit Query (in Excel 2010).

Page 15 of 16Kasper de Jonge PowerPivot Blog | Implementing histograms in Excel 2013 using DA...

5/13/2014http://www.powerpivotblog.nl/implementing-histograms-in-excel-2013-using-dax-query-ta...

Page 16: Implementing Histograms in Excel 2

from David Hager September 13, 2012 at 11:18 am

I noticed there is recommended charts in the 2013 version and did see a histogram type graph, though having trouble getting it to suggest it again. Is there an easier way, I didn’t go through as much processes as you’ve highlighted when using 2010 excel.

from Jess September 23, 2012 at 12:47 am

Hi Kasper,

cool stuff.

Thank you for sharing.

from Refa January 7, 2013 at 10:11 pm

Wouldn’t it be easier with a calculated column NRofOrders ? IMO that is actually what you do indirectly.

from Frank February 13, 2013 at 10:17 am

better late than never! just finished working through this example. as usual, thanks for your generous sharing

from greg kramer February 16, 2013 at 12:11 pm

© Kasper de Jonge PowerPivot Blog. All rights reserved. Metro Theme created by Jon Wigham. Proudly powered by WordPress.

Page 16 of 16Kasper de Jonge PowerPivot Blog | Implementing histograms in Excel 2013 using DA...

5/13/2014http://www.powerpivotblog.nl/implementing-histograms-in-excel-2013-using-dax-query-ta...