General way of pointing at All member of a hierarchy - ssas

In our cubes it is somewhat hit and miss what the "All" member of each hiearchy is called:
For different hierarchies:
HierX = [All]
HierY = [All Y]
HierZ = [All]
HierJ = [All Js]
So sometimes the cube developer has left the default and other times he has made the name more verbose.
In my mdx I would like to be able to always find this member without worrying what it is named.
Assuming the hierarchy actually has an All member, can I assume that this code will always work? :
[DimensionX].[HierarchyX].members.item(0).item(0)
Is there a more water-tight approach?

I believe [All] is what you need :
select [Geography].[Geography].[All] on 0 from [Adventure Works]
will show :
All Geographies
$80,450,596.98
To my knowledge [All] is a shortcut to the all-member of a hierarchy,

Related

Tableau How to color a chart based on two fields, one continuous and other discreet

I have a data set from Kaggle and here is what it looks like:
Now I want to plot a map using Tableau which illustrates the advantage/disadvantage of Republican/Democrat. Just picture this, because I have already had the total votes of each party in every single county, it is easy to compare which party won a county. My idea is depicting this fact: if a county is won by Republican, then it should be in red; if by Democrat, it would be in blue; otherwise it would be white if being won by minor parties (I am not sure whether there was such a case).
Note that if the more overwhelming a party is within a county, the darker should the color be. For example, if a Republican won a county tinily by 0.1%, it should be light red; if a county is won by Democrat with a landslide, say 30%, then it should be deep blue.
My problem now is that with the given data, I have no ideas about how to demonstrate the gap of votes between different parties. I guess I might need to create a calculated field that shows the vote difference with a county. But is it the right solution?
---- EDIT----
I found an example: https://public.tableau.com/profile/clillich.kltv#!/vizhome/ElectionResults_5/Dashboard1, it looks good to me. It is just uncertain what its data source looks like.
The example you have shown is perhaps not related to chart as you want. It shows only one measure. Please proceed like this.
Step-1 Create a calculated field win margin in percent with the following calculation
IF [Won] = TRUE then ([Total Votes] -
{FIXED [State],[County] : MAX(
IF [Won] = FALSE then [Total Votes] END )})/
{FIXED [State],[County] : SUM([Total Votes])}
END
Step-2 Convert it to dimension (by right clicking it).
Step-3 simultaneously create a group on party field as desired.
Step-4 select both fields in dimension pane and create a new hierarchy (party-group first and win margin second). Drag this heirarchy to marks card. Convert both to colors. The following gif may help
I think this serves your purpose. Good luck

Coalesce returning wrong value after a function call followed by multiplication

I have a report that presents information and I'm getting inconsistent information based on what appears to be some issue with a SQL view or possibly a SQL Function nested within the view. I've tried finding a way to debug the SQL View, however, it looks like SSMS only will debug Stored Procedures, so I'm not really sure how to step through and see what is happening. It really has me stumped and I can't help but wonder if it isn't a rounding issue.
GetItemAverageCost RETURNS DECIMAL(12,2) and the DataType in sitli.QuantityIssuedAtStockUOM is System.Int64 / bigint (sidenote: I'm confused about why LINQPad shows 2 data types for that column. In the tree on the left, after expanding the sitli table and hovering over the QuantityIssuedAtStockUOM the balloon BigInt NOT NULL pops up, but when I Take(100) and hover over the column in the result set it says System.Int64). Anyroad, here is the COALESCE function.
COALESCE((dbo.GetItemAverageCost(ItemModel.IDItemModel)*sitli.QuantityIssuedAtStockUOM) / ISNULL(NULLIF(ItemModel.UOMFactor, 0),1),0) -- 259.73
--ROUND(COALESCE((dbo.GetItemAverageCost(ItemModel.IDItemModel)*sitli.QuantityIssuedAtStockUOM) / ISNULL(NULLIF(ItemModel.UOMFactor, 0),1),0),2) -- 259.73
--COALESCE(ROUND((dbo.GetItemAverageCost(ItemModel.IDItemModel)*sitli.QuantityIssuedAtStockUOM) / ISNULL(NULLIF(ItemModel.UOMFactor,2), 0),1),0) -- 259.70
--COALESCE((ROUND(dbo.GetItemAverageCost(ItemModel.IDItemModel),2)*sitli.QuantityIssuedAtStockUOM) / ISNULL(NULLIF(ItemModel.UOMFactor, 0),1),0) -- 259.73
original / wrong coalesce:
COALESCE(dbo.GetItemAverageCost(ItemModel.IDItemModel)*sitli.QuantityIssuedAtStockUOM,0)
I'm not sure what else to include, but I haven't found many resources online that offer insight into this kind of a situation. Many thanks in advance for your time.
EDIT: GetItemAverageCost:
ALTER FUNCTION GetItemAverageCost
(
#IDItemModel varchar(8000)
)
RETURNS DECIMAL(16,4)
--RETURNS DECIMAL(12,2)
AS
BEGIN
RETURN
(
SELECT
COALESCE(AVG(poli.UnitPrice),0) as AvgCost
-- COALESCE(ROUND(AVG(poli.UnitPrice),0),2) as AvgCost 260.00
FROM ItemModel im
LEFT JOIN VendorItem vi
ON im.IDItemModel = vi.IDItemModel
JOIN POLineItem poli
ON vi.IDVendorItem = poli.IDVendorItem
WHERE
im.IDItemModel = #IDItemModel
GROUP BY
im.IDItemModel,
im.ItemNumber
)
END
To fix; have your function return 16,4 instead of 12,2 and then ROUND two two decimals after multiplying by the quantity.
"When a given report is run, there are no errors thrown. But the calculations are off. For example a part number 12 shows a quantity of 24 were issued at a cost of $259.73. However, each part costs $10.82 so the calculation should be $259.68. I'm not sure where the difference of 5 cents is coming from. The $259.73 is the result of the COALESCE function above. Hopefully this makes sense"
Run the SQL only for part 12 independent of the function and you'll see the average is 10.822083333333333333333333333333 (10.82 5/24ths)
24*unitprice = $259.73
unitprice = 259.73/24
unit price = $10.82 5/24.
You'll see the variance is $.05
10.82 5/24ths. *24 = 259.73
10.82 * 24 = 259.68
That difference of 5cents doesn't go evenly into the remaining 24. thus the rounding error when using your function.
When you think of going to the store and buying something it's always at amounts to the whole penny. When you go to the gas station they charge to the nearest .00001 cents. (or in your case 4 decimals)
The rounding when using fractions of pennies isn't done until multiplied by the quantity or when actual cash needs to change hands. If done too early you get rounding errors you are seeing.
Thus you eliminate over/under charging rounding errors and at most you'll charge a fraction of a penny less or more than you should.
Okay, so many thanks to all who helped along the way. There were a couple of issues preventing me from getting the correct answer. For one thing, I was working with the incorrect expression for much of the time. Secondly, after I figured out which expression to use, it was a matter of placing the ROUND function in the correct place.
So, the expression I should have been using to get my average cost is:
COALESCE(dbo.GetItemAverageCost(Item.IDItemModel) / ISNULL(NULLIF(UOMFactor, 0),1),0)
When I moved this into the WorkOrderItemInstructionPartCosts View, my report was then producing $10.82. Then I added *sitli.QuantityIssuedAtStockUOM to the line and was getting $259.73. Then I applied the ROUND function to the COALESCE function and voila! the correct value ($259.68) is being produced.
The final line looks like this:
ROUND(COALESCE(dbo.GetItemAverageCost(ItemModel.IDItemModel) / ISNULL(NULLIF(UOMFactor, 0),1),0),2)*sitli.QuantityIssuedAtStockUOM
Once again, thank you to all who helped me in the effort to resolve this and sorry for not having accurate information to begin with.
Best,
Jonathan

How to make a indirect relation between two or more instances in Protégé

First of all, my English is poor, so sorry if my writing is confusing.
I'm trying to create the following relationship between instances: if A propertyX B, and C propertyY A, then C propertyX B. In my case, I want to specify that if a ManagerA "manages" an employee, and ManagerB has the same job as ManagerA, then he also manages the same employee.
I tried to use chain properties to do that, but the reasoner (FaCT ++ 1.6.5) doesn't work when I activate it (the log says a non-simple property is being used as one). I think the problem is in the fact that the property "manages" is asymmetric and irreflexive and the property "sameJob" is transitive and symmetric, but I'm not sure if that's the case. I applied the chain property in the "manages" property, stating: sameJob o manages SubPropertyOf: manages.
I'm just starting with Protégé and will appreciate any help a lot.
The reason for the error is due to manages not being a simple role, i.e. if you have r1 o ... o rn subPropertyOf r where n>1 then r is a non-simple role. Non-simple roles cannot be used in IrreflexiveObjectProperty and AsymmetricObjectProperty. See section 11 of OWL 2 syntax. The reason for the constraint on roles is to maintain decidability.
However, you can achieve the desired result by adding a SWRL rule:
manages(?x, ?y) ^ sameJob(?x, ?z) -> manages(?z, ?y).

How to calculate complexity of this recurrence?

I have this recurrence:
I want to apply the Master Method because it seems to belong to the Case 1, so I want to probe that:
But I don't have any clue about how can I do it. Am I on the right way ?

Netlogo: Choosing an agent to run a procedure from variable values

I am creating a taxi-like simulation in which vehicles search for customers. When a vehicle is within 1 unit distance of the customer, it picks up the customer and takes it to its destination (and begins searching for customers again, etc.).
My issue: if 2 vehicles come within 1 unit distance of the same customer within the same time-step, I need the vehicle with the highest [rating] (vehicles-own variable) to always get the customer. This is my code (updated from a previous post):
to find-customers
if (distance closest-customer <= 1)
[ask closest-customer [check-for-vehicles]]
end
to check-for-vehicles
set competitors vehicles in-radius 1
determine-highest-rated
end
to determine-highest-rated
set highest-rated max-one-of competitors [rating]
ask highest-rated [set color red]
end
[competitors] and [highest-rated] are waiting-customer-own variables. closest-customer is min-one of waiting-customers (distance myself). Normally [set color red] would run the procedure in which the vehicle gets the customer transport information. When forcing two vehicles on the same customer, the correct vehicle always sets its color red. Sometimes the incorrect vehicle also sets its color red. When I check the variable values for the waiting-customer, the correct vehicle is identified as highest-rated, yet sometimes the other vehicle still turns red. There is obviously a mistake with how I've set up the procedures. If anyone has suggestions on how to fix this (or how to approach this task differently) it would be appreciated.
I think the reason why your ifelse always return false is because the ifelse is placed at the same time step as the initialization of identificationfor each taxi.
The way netlogo works when running some function to an agenset is, each agent, one by one will individually run the function in random order, not in the same time.
So, if the ifelse is placed just right after the identification is set and in the same function, it will always return false since the other vehicles haven't got their identification set yet. Then it will directly run make-deal before even compare it to other-vehicles.
for example:
ask vehicle [
set identification ...
ifelse ... [..]
[..]
]
is different with
ask vehicle [set identification ...]
ask vehicle [ifelse .... [...][...] ]
The first one will make each agent set their identification and do the ifelse statement before make other agent do.
The second one will make every agent set their identification first then make every agent do the ifelse statement.
The conclusion is, I suggest you to separate the find-costumer function and the make-deal function.
I hope this helps