williamweber.net
  • Home
  • About
Follow

Posts tagged Scripts

Named Set Sub-totals in Excel using VisualTotals()

Feb22
2012
Leave a Comment Written by Will

This is just a quick tip for fixing the default Analysis Services (SSAS) named set sub-total behavior in Excel 2010. Normally when you select a named set for the rows or columns of a pivot table you don’t get a sub-total. Which, for me, removes a lot of the usefulness of the named set. Thankfully it’s a relatively easy fix. It just takes a little additional MDX in your named set definition.

Enter: VisualTotals() (msdn function reference)

The VisualTotals() function dynamically totals child members in a set. By adding the “All” member for whatever hierarchy you’re building your set from and wrapping the whole set in the VisualTotals() function you can get Excel to treat the named set just like any other group/hierarchy when it comes to sub-totals.

Typically if you created a set like this one (all examples from Adventure Works):

WITH SET [Amasia] AS
{
	[Geography].[Country].&[United States]
	,[Geography].[Country].&[Canada]
	,[Geography].[Country].&[Australia]
}

You’d see something like this:

no sub-totals

If instead you create your set like so:

WITH SET [Amasia] AS
VisualTotals(
	{
		[Geography].[Country].[All Geographies]
		,[Geography].[Country].&[United States]
		,[Geography].[Country].&[Canada]
		,[Geography].[Country].&[Australia]
	}
)

You’ll get a nice little sub-total at the bottom.

Yey! sub-totals

One thing to note is that you need to put the “All” member at the beginning of your VisualTotals set. Otherwise it won’t be correctly filtered by the children that follow and you’ll end up with a sub-total that is actually the full, unfiltered total of the “All” member.

  • Share this:
Posted in BI - Tagged BI, MDX, SSAS

MDX: Scope Statement For All Measures in Multiple Measure Groups

Dec06
2011
Leave a Comment Written by Will

This was irritating me today so I thought I would share. If you need to write a scope statement that will include all the measures in multiple measure groups; perhaps you’re implementing some Time Intelligence calculations and you want to have any new measures dynamically included, then the statement looks a little something like this:

SCOPE({MeasureGroupMeasures("Internet Sales"), MeasureGroupMeasures("Reseller Sales")});

I forgot the {} the first time around and was super confused by an error message when I attempted to deploy the MDX calculation to the cube that said that said “The END SCOPE statement does not match the opening SCOPE statement.” Because my SCOPE and END SCOPE statements looked just fine to me.

  • Share this:
Posted in BI - Tagged Analysis Services, MDX, SSAS

Table Disk Space Usage By Filegroup and Partition

Apr06
2009
5 Comments Written by Will

I wanted a more granular level of detail when looking at disk space usage of our databases. I wanted to see the disk usage of each table. Since we use partitioning pretty heavily I also wanted to see how that usage was broken out by partition and filegroup. In our implementation we have a separate filegroup for each table partition but in a configuration that has multiple parititons on a partition this script can tell you usage for either metric.

Normally I’ll take this query and take the results over to excel and pivot the data so that I can filter and sum data in whatever way I want. I also have this running in a SQL Agent job and inserting into a table so that I connect to that table and do growth trend analysis.

READ MORE »

  • Share this:
Posted in SQL Server - Tagged DBA, Partitioning, T-SQL

Database File Auto-Growth History

Apr05
2009
Leave a Comment Written by Will

Here’s a quick script to find the recent history of file auto growth on a MSSQL system. I work with a large OLTP database that’s partitioned monthly. If we get files auto-growing toward the end of a month when the partition is already upwards of 60GB, timeouts start to crop up. Sometimes finding out where those timeouts are coming from aren’t readily apparent. This script helped us out when we were searching for recent file growth.

 

SET NOCOUNT ON
 
DECLARE  @path VARCHAR(MAX), @cmd VARCHAR(4000);
 
SELECT @path = CONVERT(VARCHAR(MAX),VALUE)
FROM fn_trace_getinfo(DEFAULT) WHERE property = 2
SET @cmd = 'dir /b "' + @path + '"'
-- PRINT @cmd
 
DECLARE @files TABLE
(
	fn VARCHAR(64)
) 
 
INSERT @files
EXEC master..xp_cmdshell @cmd
 
DELETE @files
WHERE fn IS NULL
 
SELECT
	e.DatabaseName
	, e.[FileName]
	, e.SPID
	, e.Duration
	, e.StartTime
	, e.EndTime
	, CASE e.EventClass
		WHEN 92 THEN 'Data'
		WHEN 93 THEN 'Log'
	END AS 'FileType'
	, f.fn AS 'TraceFile'
	, te.name
FROM @files f
	CROSS APPLY fn_trace_gettable(@path, DEFAULT) e
	JOIN sys.trace_events te
		ON e.EventClass = te.trace_event_id
WHERE
	e.EventClass IN (92,93)
ORDER BY
	e.StartTime DESC
  • Share this:
Posted in SQL Server - Tagged DBA, T-SQL

Recent Posts

  • Thoughts on Killzone 3 Multiplayer Going Free-to-Play (or is it Free-to-Pay?)
  • A Game Funding Revolution
  • Named Set Sub-totals in Excel using VisualTotals()
  • New Camera Please. – Mirrorless ILC Goodness
  • Formatting Map Legends in SQL Server 2008 R2 Reporting Services

From Twitter:

  • I thought we were past the whole "justify Apple, vilify Microsoft for the same thing" thing these days. http://t.co/u6jG58uB 5 days ago
  • Benjamin Franklin was awesome. Oh and something about Assassin's Creed 3, but who cares. http://t.co/nsEeye01 2 weeks ago
  • Ever spent an hour figuring out how to add a column of data to your warehouse only to find that it was already there? Consistent naming FTW. 2 weeks ago
  • More updates...

Posting tweet...

Powered by Twitter Tools

Categories

  • BI
  • Gaming
  • Opinion
  • Photography
  • Reporting
  • Scripts
  • Social Games
  • SQL Server
  • XNA

Archives

  • March 2012
  • February 2012
  • January 2012
  • December 2011
  • October 2011
  • September 2011
  • April 2011
  • January 2011
  • December 2009
  • July 2009
  • April 2009
  1. We welcome any feedback, questions or comments

EvoLve theme by Theme4Press  •  Powered by WordPress williamweber.net