SSAS - Data Cube Hierarchy not visible in Excel - ssas

Initial Request: Create hierarchies over customer names and product descriptions.
Problem: I created several similar hierarchies and the product description hierarchy is not visible in Excel
Supporting details
The computed columns for each hierarchy look like this:
Column Name: Product Description Prefix1
Expression:
CASE
WHEN [ProductDescription] = 'N/A' THEN 'N/A'
ELSE LEFT([ProductDescription], 1)
END
Column Name: Product Description Prefix5
Expression:
CASE
WHEN [ProductDescription] = 'N/A' THEN 'N/A'
ELSE LEFT([ProductDescription], 5)
END
Column Name: Product Description Prefix10
Expression:
CASE
WHEN [ProductDescription] = 'N/A' THEN 'N/A'
ELSE LEFT([ProductDescription], 10)
END
In my product dimension, I created a Product Description Hierarchy that is leveled
Product Description Prefix1
Product Description Prefix5
Product Description Prefix10
Product Description
With 1 being an attribute relationship to 5, 5 to 10, 10 to Product Description, and Product Description to the Key: Product.
Each one of these attributes have their KeyColumn collections are set:
Product Description Prefix1's KeyColumns: Being its self
Product Description Prefix5's KeyColumns: 1 and 5
Product Description Prefix10's KeyColumns: 1,5,10
Product Description's KeyColumns: 1,5,10, and Product Description
Right now, I'm choosing AttributeHierarchyVisible = False because I don't want the user to to be able to select the individual attribute.
Any help as to what I am missing causing the hierarchy to become visible would be much appreciated

The solution to this issue lies in the naming of the computed columns.
You have spaces in the names of the computed columns.
With the spaces, the data correctly deployed where it should have; however, Excel 2010 would not acknowledge the existence of a hierarchy -- even though the data was visible through management studio. Strange.
Once the spaces are removed and the cube deployed, the hierarchy will be visible.

Related

Sum and group products by similar codes/category

My problem is that in the supplier's invoices I have the same product with different names. The goal I'd like to reach is to group them in a single product code/category. Do you think is possible?
I want to sum specific record in my SQL Server table. I have something like this
Description
Quantity
Phone X
10
AB Laptop B
20
X Phone
15
Laptop C
20
AB Phone X
5
And I have to sum "Phone" and "Laptop", to obtain a table like this
Description
Quantity
Phone
30
Laptop
40
I have no idea which query is correct to use. The problem is the words "Laptop" and "Phone" contains other words, and I can't sum them.
Can someone help me, please?
Word of Warning:
As others mentioned, parsing string values this will probably lead to data issues. Maybe not today, but down the road. For example, what if someone listed "Laptop w/ built in wireless phone charger". Depending on how this query is used, could cause significant issues.
Recommended Approach to Categorizing Data:
I've worked with many external data feeds and if it were me, I'd recommend doing one of the following:
Define a list of your own product categories and have your vendors map to them in their data feeds
Ask your vendors to add their own internal product category to the data feed, and then map their categories to your own
There are pros and cons to both approaches, but both would consistently provide accurate data.
Group By Category from Key Word in Description
With that fair word of caution, here's how I'd do it if you can't have your vendors change their data feeds:
SELECT Category
,TotalQuantity = SUM(Quantity)
FROM YourTable AS A
CROSS APPLY (
SELECT Category = CASE
WHEN [Description] LIKE '%Phone%' THEN 'Phone'
WHEN [Description] LIKE '%Laptop%' THEN 'Laptop'
ELSE 'Other'
END
) AS B
GROUP BY Category
Stephan's answer was my first thought +1, however, I tend prefer to keep such items in generic mapping table and not code ... too many touchpoints
Imagine #Map was a physical table
Example
Declare #Map Table (Item varchar(50))
Insert Into #Map values
('Phone')
,('Laptop')
,('Cable')
,('Battery')
Select ItemGrp = coalesce(B.Item,'Undefined')
,Quantity = sum([Quantity])
from YourTable A
Left Join #Map B on [Description] like '%'+Item+'%'
Group By B.Item
Results
ItemGrp Quantity
Laptop 40
Phone 30
Of course this could be done in SQL alone, but since you have tagged with vb.net, maybe you want a .NET solution. Also, since you supplied no code, I will make some up
Public Class Data
Public Property Description As String
Public Property Quantity As Integer
End Class
Dim datas = New List(Of Data)()
datas.Add(New Data With {.Description = "Phone X", .Quantity = 10})
datas.Add(New Data With {.Description = "AB Laptop B", .Quantity = 20})
datas.Add(New Data With {.Description = "X Phone", .Quantity = 15})
datas.Add(New Data With {.Description = "Laptop C", .Quantity = 20})
datas.Add(New Data With {.Description = "AB Phone X", .Quantity = 5})
Dim groupedRecords = datas.
GroupBy(Function(r) If(r.Description.ToUpper().Contains("PHONE"), "Phone", "Laptop")).
Select(Function(g) New With {.Description = g.Key, .Quantity = g.Sum(Function(i) i.Quantity)})
For Each record In groupedRecords
Debug.Print($"Description: {record.Description}, Quantity: {record.Quantity}")
Next
Description: Phone, Quantity: 30
Description: Laptop, Quantity: 40
If you add more products, this will break. It recognizes anything with "phone" in the description in it as a Phone, and anything else as a laptop.

VS SR Report joining data from multiple Data sets?

Wondering if anyone can help me, I am currently learning, SRSS Reports and have been tasked with a Pay & Display vehicle registration report, for staff and student carparks, to show if they are registered for P&D. I have the report laid out as a 3 table column; Name, Vehicle Number and Vehicle Registration. I have from the below code set out in my datasets the Vehicle Number and Vehicle Registrations pulling through, with a parameter to filter out if is staff or student pay and display. However I am having difficulty with pulling the Staff and Student names into one name column as they are through two different datasets. Can anyone be of help at all please? TIA
**-- Pay & Display Carpark Details Dataset**
SELECT * FROM Carpark_Vehicles
WHERE VehicleCustNo IN (SELECT CustID FROM [dbo].[Carpark_Customer]
WHERE CarParkID IN (SELECT CarParkID FROM [dbo].[Carpark_CarPark]
WHERE CTypeID IN ('PD', 'SPD')))
--and CTypeID IN (#Carpark_type))
**--Vehicle Details Dataset**
SELECT
Carpark_Vehicles.VehicleID
,Carpark_Vehicles.RegNo
,VehicleCustNo
FROM
Carpark_Vehicles
WHERE CarPark_Vehicles.RegNo = #RegNo
**--Staff details dataset**
SELECT
StaffDetails_StaffandLeaverDetails.StaffNumber
,StaffDetails_StaffandLeaverDetails.LastName
,StaffDetails_StaffandLeaverDetails.Name1
FROM
StaffDetails_StaffandLeaverDetails
**--Student details dataset**
SELECT
Student_CurrentStudentDetails.StudentNumber
,Student_CurrentStudentDetails.StudentID
,Student_CurrentStudentDetails.LastName
,Student_CurrentStudentDetails.FirstName
FROM
Student_CurrentStudentDetails
**--Carpark permit type (Pay & Display) parameter**
SELECT DISTINCT
CTypeID, CASE CTypeID WHEN 'abc' THEN 'Students' WHEN 'abc' THEN 'Staff' END AS Label
FROM
Carpark_Customer
WHERE CTypeID IN ('abc', 'Abc')
For your req I just took some sample data. This entire example will give you Idea how to achieve your final result.
Note: this is just showing you way how to achieve it, you have to modify as per your req.
Student and Staff Info from 2 different Tables
Registration Info from another separate Table
Your Final Result when Student as parameter is selected
Your Final Result when Staff as parameter is selected
Now how did I achieved this?
My Design for Final Result
Row visibilty expression for your final result Table in SSRS
Expressiion as below
=IIF(Parameters!ReportParameter1.Value=1,
IIF(Isnothing(Lookup(Fields!PersonId.Value,Fields!PersonId.Value,Fields!Name.Value, "DSStudentInfo")),true,false),
IIF(Isnothing(Lookup(Fields!PersonId.Value,Fields!PersonId.Value,Fields!Name.Value, "DSStaffInfo")),true,
false)
)
first Name column visibility
second column name visibility
First Name data value expression
=Lookup(Fields!PersonId.Value,Fields!PersonId.Value,Fields!Name.Value, "DSStudentInfo")
second name data value expression
=Lookup(Fields!PersonId.Value,Fields!PersonId.Value,Fields!Name.Value, "DSStaffInfo")

Need some advice writing a sql query

I have a view with columns [Date], [ProductId], [NewProduct]. Where [Date] is always [yyyy-mm-01], so for a given month, [NewProduct] can either be 1 or 0 for any productId.
I am trying to create another view based on this one but I want to implement one change. If a product has been marked as [NewProduct] for a given month then it should be marked as a [NewProduct] for the remaining months of that year.
Example This is my original view: ProductView1
As you can see product: 261220 is marked as new product for 2018-05-01.
What I want is I want to create another view derived from this view which should have product: 261220 marked as new product for the rest of the 2018.
I am trying to write a query like this:
CREATE View [dbo].[ProductView2]
As
SELECT [ProductView1].[Date]
,[ProductView1].[ProductId]
,Case WHEN ([ProductView1Prev].[New Product] = 1 AND Month([ProductView1Prev].[Date]) <> 12)
THEN 1
ELSE [ProductView1].[New Product]
END AS [New Product]
FROM [dbo].[ProductView1]
left join
[ProductView1] as [ProductView1Prev]
ON [ProductView1].CustomerId = [ProductView1Prev].CustomerId
and [ProductView1].[Date] = dateadd(month,+1,[ProductView1Prev].[Date])
But the new view Mark product: 261220 as a new product for the next month rather than all the remaining months for that year.
ProductView2 looks like this based on my query:
I am not sure how to achieve the desired output.
try using a "trigger after update" with checking conditions (month bigger than this month by where clause) and check if this column updated then update other columns as well.

SSRS is removing multiple lines in grouping

I have an SSRS report with the following query:
SELECT DISTINCT
Rtrim(ltrim(CUSTNAME)) as 'CUSTNAME',
ItemName,
ISNULL(NAME, LOGCREATEDBY) AS 'Modified By'
,b.ITEMID as 'Item Id'
,[PRICE_NEW] as 'New Price'
,[PRICE_OLD] as 'Old Price'
,[PRICEUNIT_NEW] as 'New Unit Price'
,[PRICEUNIT_OLD] as 'Old Unit Price'
,LOGCREATEDDATE as 'Created Date'
,LOGCREATEDTIME
,(select Description from Dimensions where a.Dimension2_ = Dimensions.Num) as 'Division'
,(Select TOP 1 INVENTTRANS.DATEFINANCIAL From INVENTTRANS Where
INVENTTRANS.ITEMID = B.ITEMID and InvoiceID like 'Inv%' order by INVENTTRANS.DATEFINANCIAL desc) As 'LastInvoice'
FROM PMF_INVENTTABLEMODULELOG AS b
LEFT JOIN USERINFO ON ID = LOGCREATEDBY
LEFT JOIN INVENTTABLE AS a on a.ITEMID in (b.itemId)
WHERE LOGCREATEDDATE between #beginCreatedDate and #endCreatedDate
and a.dimension2_ in (#dimension)
order by LOGCREATEDDATE,LOGCREATEDTIME desc
What happens, in short, is it goes through a table and picks out an item number and lists each price change for that item.
the query, wen run, will return something like:
CUSTNAME | Modified By | Item ID | New Price | Old Price
------------------------------------------------------------------
Performance Joe 12345 21.50 21.49
Performance Mary 12345 21.49 19.10
(This happens to be the return that is causing problem)
My report lists each line by division, Customer name and item Number. The problem is, when I have an Item ID group, it adds up the total (makes sense) So i get rid of the item number group, but now it will list only one item per customer!
it should show the two lines for Performance in the example, but instead, it lists neither. I would like it to show every single line for each customer. It must be the ITEM ID group, but I can't seem to get it right.
Rather than getting rid of the group, change it to show detail data.
Right click on the group select 'Group Properties' and select the Group On expression. Then click the delete button. It will then no longer sum as it is a detail group.
I would recommend that you then remove sum from the relevant expressions, to avoid confusion, as they will only be summing single values but will make it look otherwise.

Any Mysql guru who knows how to handle a custom group calculation scenario in 1 query?

I hope any sense can be made from my explanation. I was able to create the query, however my query only works for Items related to Containers, AND only if no more than one Items are related. I really hope anybody can be of any assistance!
Consider the following objects:
Container
Person
Item
I have one table where instances of all objects are stored. The table uses a self-referencing parent-child construction so it is db-technically possible to put a Container 'inside' a Person (just mentioning, this is not happening).
Object_Instances
objectid
parentid
typeid
typespecification (same as containerid, personid or itemid => one of three is filled)
containerid
personid
itemid
I have two tables which can be used to link persons/items to containers:
Container_Person
containerid
personid
amount
required (boolean)
Container_Item
containerid
itemid
amount
required (boolean)
(there are also a person/*item* table)
Now for an instance of a container I would like to calculate a number between 0 and 1 which is based on the related Container_Person and Container_Item specification in the following way:
if NO Container_Person/Container_Item are related to the Container => result = 1
if there are related records they should be taken into account in the following manner:
if the Container DOES NOT contain (has a child record of) ALL of the related persons/items which are required => result 0
otherwise:
result = average based on:
(# child records vs amount in Container_xxx relation)
if there are more than 1 person or item related to the container then the 'weight' for the (#records vs amount) value should be the ratio between the related Container_xxx.amount values for that Container.
Here is my current 'solution':
This query only works for one related item to a container. It doesn't take persons into account in any way... If more than one item are related to the container then the query returns multiple records.
So my actual question is: How can I group/sum(calculate to 0 - 1 decimal) the results of the following query based on the _Person / _Item related amount/required specification?
SELECT
Container.name,
Item.name,
(ifnull(Sum(Object_Instance.amount),0) / Container_Item.amount) as value
FROM
Container
Inner Join Object_Instances as Containers
ON Containers.typeid = 'container'
AND Container.containerid = Containers.typespecification
Left Outer Join Container_Item ON Container_Item.containerid = Container.containerid
Left Outer Join Item ON Item.itemid = Container_Item.itemid
Left Outer Join Object_Instance as ContainerItems
ON Item.itemid = ContainerItems.typespecification
AND ContainerItems.typeid = 'item'
AND ContainerItems.parentid = Containers.objectid
WHERE Containers.objectid = 1
GROUP BY
Container.name,
Container_Item.amount,
Item.name,
Container.containerid
When doing complex joins and grouping I will often have to resort to this type of query:
Create grouped (or unique) list
In a new query take the grouped list and then join in a ungrouped list that provides additional details that are needed.