Is there a way to roll data up that looks like this:
What I am looking for is this:
Y:\\Data\\FS02-V\\Aetna\\ETL | Data, development files
So rows two and three being children of row one should roll up to the parent and the parent should show all file types contained. I am working in sql server and this is the code that produces the source table:
SELECT
[MCL].[Category Description] As Category
, [SF].[Directory] as Directory
, CONVERT(BIGINT, [SF].[Length]) AS FileSize
, (SELECT MAX([Id]) FROM [dbo].[split](RIGHT([SF].[Directory],LEN([SF].[Directory])-1),'\')) AS [LevelsFromRoot]
FROM [dbo].[FS02V_SourceFiles] [SF]
INNER JOIN [dbo].[Extensions] [E]
ON [SF].[Extension] = [E].[Extension]
INNER JOIN [dbo].[MasterCategoryLookup] [MCL]
ON [MCL].CategoryID = [E].Category
ORDER BY [SF].[Directory]
Table def:
CREATE TABLE [dbo].[FS02V_SourceFiles](
[Length] [float] NULL,
[Directory] [nvarchar](255) NULL,
[Extension] [nvarchar](255) NULL,
[Type] [nvarchar](max) NULL
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
CREATE TABLE [dbo].[Extensions](
[Extension] [nvarchar](255) NULL,
[Type] [nvarchar](max) NULL,
[Category] [int] NULL
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
Split function:
ALTER FUNCTION [dbo].[Split]
(
@RowData nvarchar(max),
@SplitOn nvarchar(5)
)
RETURNS @RtnValue table
(
Id int identity(1,1),
Data nvarchar(max)
)
AS
BEGIN
Declare @Cnt int
Set @Cnt = 1
While (Charindex(@SplitOn,@RowData)>0)
Begin
Insert Into @RtnValue (data)
Select
Data = ltrim(rtrim(Substring(@RowData,1,Charindex(@SplitOn,@RowData)-1)))
Set @RowData = Substring(@RowData,Charindex(@SplitOn,@RowData)+1,len(@RowData))
Set @Cnt = @Cnt + 1
End
Insert Into @RtnValue (data)
Select Data = ltrim(rtrim(@RowData))
Return
END
The path(Directory) is stored as nvarchar and it should be the driver to roll up to the parent. I would assume the path needs to be split and my function is already doing something similar to get the path levels. I think this would be easier in SQL with my raw data but at the end of the day I am going to be visualizing this data in tableau so if anyone knows if its easier to use sql for this before I feed it into tableau or just use tableau with my source data I would try that as well.
Solution to this was simple:
Use abolve SQL to prepare the directories and group them with their respective files and then roll it up using Tableau and calculated fields.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.