SSAS Olap Cube Calculated Column in .dsv - ssas

I'm trying to create the calculated column 'TotalWeight' (table SP) based on 'Quantity' column (table SP) and 'Weight' column (table P).
I can't figure it out, how to write expression. The one I tried doesn't work.
[SP.Quantity] * [P.Weight]

You have two options. First you could convert the table to a view in the database and do the join there. However if you prefer to do this in the DSV some syntax like the following will work. Not knowing your exact table names I guessed and hope you can extrapolate to your table names. Let’s call p the Product table. And let’s call sp the SupplierProduct table which is where you are putting the calculated column.)
Change the calculated column definition to:
Quantity * (select P.Weight from Product p where p.ProductID = SupplierProduct.ProductID)

Related

How to see pull up all relevant info from a table given a list of values SQL

Currently I have a list of manufacturing numbers in a table called "Mfr_Numbers_Table".
I also have a master table called Billings
I would like to generate a query where I see all line items that matches with what is on Mfr_Numbers_Tables from the Billings Table.
How do I do this? I can just write 50 queries with a where clause being the Mfr_numbers, but that would take too long.
You need put the tables in a relation in your query.
This is done by a join on the tables on a field which is in both of them.
For example if this field is named MfrNumber:
Select Billings.*, Mfr_Numbers_Table.*
From Mfr_Numbers_Table Inner Join Billings
On Mfr_Numbers_Table.MfrNumber = Billings.MfrNumber
Usually you don't select all fields from all joined tables, but select what you really need.
Also you can still filter (Where) and/or order (Order By) the result.
The name of the joined field isn't relevant, but its datatype and for sure the content.
For more please read this article: Join tables and queries

Make calculated column from other table

I want to make a calculated columns from different tabel, i want to calculate TotalPrice from table A, which is from Quantity on Table B, and UnitPrice on Table C.
sorry for my bad english
Like #marc_s explain you, you can create computed only with column of the same table. If you want a "table" with a calcul between multiple table you can create simply a view.
Create view on SQL SERVER

Spotfire - Getting data from one table that falls between two dates in another table and adding to a calculated column

What would be the expression to create a calculated column in Table Example 2 called "SZODMAXCALC", that would contain the SZODMAXCALC from Table Example 1 given that the data from Table Example 1 falls between the dates (DTTMSTART and DTTMEND) within Table Example 2?
Maybe this is easier done on the SQL side that loads the data?
there is no way to create a calculated column that references a column in another table.
you will need to do a join either in Spotfire (via Insert...Columns)* or on the SQL-side of things (either via a view on your database or by creating a new information link in Spotfire).
the best method depends on your data structure, implementation, and desired results, so I'm not able to recommed there. take a look at both options and evaluate which one works best.
* NOTE that Spotfire cannot join based on a Calculated Column as a common key. that is, using your example, if [WELLNAME] is a calculated column, you cannot tell Spotfire the equivalent of SELECT wellname, ... FROM table_a LEFT JOIN table_b ON table_a.wellname = table_b.wellname.
the alternative is to Insert...Transformation and choose Insert New Calculated Column, and to join on that instead.
the reason for this is that calculated columns are very mutable; they could change frequently based on a user action. it would be inefficient to re-execute the join each time the column's contents changed. conversely, a "Transformation Calculated Column" is only updated when the data table is loaded.

Need HELP! with - SQL Plus Select multiple columns

Hi I am using sql plus and I need to select 5 columns from 4 tables and show the result. This is the code that i used and the error I get.
SELECT CustomerID, OrderID, AircraftID, Quantity, TotalCost
FROM Customer_Table, Order_Table, Aircraft_Table, Orderline;
ERROR at line 1: ORA-00918: column ambiguously defined
What is the code to get these columns and display them from multiple tables. Please help with this.
The reason is that you tried to execute an SQL statement that joined two or more tables, where a column with the same name exists in both tables.
Exemple with this SQL query
SELECT suppliers.supplier_id, quantity
FROM suppliers, orders
WHERE suppliers.supplier_id = orders.supplier_id;
Since the supplier_id column exists in both the suppliers and orders table, you need to prefix the column with the table name as follows:
Moreover you need to link your tables between them. If I take the example above you should do this kind of thing
WHERE suppliers.supplier_id = orders.supplier_id;
Means you link the table suppliers with the table orders by the column supplier_id
This article may help you to understand about your issue:
http://www.sitepoint.com/understanding-sql-joins-mysql-database/
I don't know SQL plus specifically but in most SQL variants you should specify a table name then a column name. Such as SELECT Customer_Table.CustomerID ...... this will disambiguate which column should be used in the result projection.
The error means one or more of those columns exist with the same name in those tables. Thats why it does not know which column to select from what table. If you could specify the table name and then the column, I think this should go away.

SQL Query for filtering columns returned

I want to return columns based on some meta data in an other table. i.e. i have my table which contains 10 columns, and another table which contains those columns denormalise with metadata to do with them.
i.e.
Table - Car:
columns - Make,Model,Colour
and another table called "Flags" which has a row for each of the above columns and each row has a column for "IsSearchable" and "ShowOnGrid" - that sort of thing.
The query i want is one which will return all columns from the cars table that are flagged in the "Flags" table as "ShowInGrid"
----EDIT
Apologise, I should have stated that this is on SQL Server 2008.
Also, I dont want to have to physically state the columns which i would like to return, i.e. If i add a column to the car table, then add it into the Flags table and declare it to be searchable, I don't want to have to physically state in the SQL Query that i want to return that column, i want it to automatically pull through.
You need to use dynamic SQL; this can easily be done with a stored procedure.
Something like this might work:
Select
D.CarID,
Case D.ShowMake When True Then D.Make Else NULL END AS Make
...
From
(Select
C.CarID, C.Make, C.Model, C.Colour, F.IsSearchable, F.ShowOnGrid, F.ShowMake
From
Cars C
Inner Join
Flags F
On C.CarID = F.CarID) D
I didn't write in all the case statements and don't know how many flags you're working, but you can give it a try. It would require to filter on null values in your application. If you actually want the columns omitted on the basis of the Flag column value the other answer and comment are both right on. Either Dynamic SQL or build your query outside in another language first.