I am new to Cognos and I know SQL but it seems I can’t figure out cognos logic for some basic stuff. It's been two days I am trying and I have been looking all over the internet without finding anything.
Here’s the problem.
I have a Dimension Product that has two dimensions under it: type of product and article (in this order, article is below type of product in terms of hierarchy).
Let’s simplify and say I have this table:
Product line | Article | Sales
-------------------------------
Shoes | Article1 | 1000
| Article2 | 2000
| Article3 | 10
| Article4 | 20
| Article5 | 30
Bags | Article6 | 100
| Article7 | 100
| Article8 | 30
Balls | Article9 | 50
| Article10 | 50
I want to display the sales per product line and per article for article1 and article2 and the sales per product line only for the rest.
I want my final result to look like this:
Product line | Article | Sales
-------------------------------
Shoes | Article1 | 1000
| Article2 | 2000
| Other | 60
Bags | Other | 330
Balls | Other | 100
I created an elementary data with the following expression “if [article-name] in (‘article1’,’article2’) then ([article-name]) else (‘other’) but it gives me this:
Product line | ArticleNEW| Sales
-------------------------------
Shoes | Article1 | 1000
| Article2 | 2000
| Other | 10
| Other | 20
| Other | 30
Bags | Other | 100
| Other | 100
| Other | 30
Balls | Other | 50
| Other | 50
I thought Cognos would group by automatically but it seems it does not when you create a new expression….
Please note that I have thousands of articles and I cannot create a data that would say “article3+article4+article5 etc.”.
If anyone has an idea on this, it would be great!
Thank you in advance!
I believe the issue is with the model. If you have access to Framework Manager and the project/metadata, this would change my answer
Try this method: 3 queries
1) Query 1 just have product line and article
2) Query 2 product line, article, sales
3) Next go to queries, then tool box, find the join.
Drag that over. There will be spots to add query 1 and query 2
In the middle is how you define the join
Connect the product line and article (there should be a button to add links so you should have 2 lines). This will be 1 to many (1.1 to 1.n). The first part represents the type of join, 1 being inner, 0 being outer. The second part is the relationship (either 1 or n for many).
We can group by query 1 and aggregate query 2 the way we want
Double click on query 3 and drag the data items (from query 1 and query 2)
Grab sales from query 2, and everything else from query 1
Now you should be able to set the aggregate property for Sales (either total or sum)
Related
I am trying to create an MDX measure in Excel (in OLAP Tools) that will count how many members there are for every other item in another dimension. As I don't know the exact syntax and notation for MDX and OLAP cubes I will try to simply explain what I want to do:
I have a pivot table based on an OLAP Cube. I have a Machine Number field stored in one dimension, that is the "parent" and for every machine number there is a number of articles that were produced (in certain period of time). Those articles are represented by Order Numbers. Those numbers are stored in another dimension. I would like the measure to count how many order numbers there are for every machine number.
So the table looks like this:
+------------------+----------------+
| [Machine Number] | [Order Number] |
+------------------+----------------+
| Machine001 | |
| | 111111111 |
| | 222222222 |
| | 333333333 |
| Machine002 | |
| | 444444444 |
| | 555555555 |
| | 666666666 |
| | 777777777 |
+------------------+----------------+
and I would like the result to be:
+------------------+----------------+------------+
| [Machine Number] | [Order Number] | [Measure1] |
+------------------+----------------+------------+
| Machine001 | | 3 |
| | 111111111 | |
| | 222222222 | |
| | 333333333 | |
| Machine002 | | 4 |
| | 444444444 | |
| | 555555555 | |
| | 666666666 | |
| | 777777777 | |
+------------------+----------------+------------+
I've tried using the COUNT function with EXISTING as well, but it wouldn't work (always showing 1, or the same wrong number for every machine). I believe that I have to somehow connect those two dimensions together so the Order Number is dependent to Machine Number, but lacking the knowledge about MDX and OLAP Cubes I don't even know how to ask Google how to do that.
Thanks in advance for any tips and solutions.
Your problem basicly is, you have two attributes in diffrent dimensions. You want to retrive the valid combinations of these attribute, further you want to count the number of attribute values avaliable in the sceond attribute based on the value of the first attribute.
Based on the above problem statement, in an OLAP cube a fact table or a Measure defines the relations between attributes of diffrent dimension linked to the Measure\Fact-Table. Take a look at the example below.(I have used the SSAS sample db Adventureworks)
--Iam trying to find the promotions that were offered for each product category.
select
[Measures].[Internet Sales Amount]
on columns,
([Product].[Category].[Category],[Promotion].[Promotion].[Promotion])
on rows
from
[Adventure Works]
Result
The result is cross-product of all the product categories and the promotions. Now lets make the cube return the valid combinations only.
select
[Measures].[Internet Sales Amount]
on columns,
nonempty(
([Product].[Category].[Category],[Promotion].[Promotion].[Promotion])
,[Measures].[Internet Sales Amount])
on rows
from
[Adventure Works]
Result
Now we indicated that it needs to return only valid combinations. Note that we provided a measure that belonged to the fact connecting the two dimensions. Now lets count them
with member
[Measures].[test]
as
count(
nonempty(([Product].[Category].currentmember,[Promotion].[Promotion].[Promotion]),[Measures].[Internet Sales Amount])
)
select
[Measures].[Test]
on columns,
[Product].[Category].[Category]
on rows
from
[Adventure Works]
Result
Alternate query
with member
[Measures].[test]
as
{nonempty(([Product].[Category].currentmember,[Promotion].[Promotion].[Promotion]),[Measures].[Internet Sales Amount]) }.count
select
[Measures].[Test]
on columns,
[Product].[Category].[Category]
on rows
from
[Adventure Works]
Within a resource planner, my data has a row for each employee, and columns detailing the team they work for. Another column details the available days they will work in the year. The teams are also displayed along a row at the top, see below :
A | B | C | D | E | F | G |
1 Employee | Team 1 | Team 2 | Days | Finance | Risk | IT |
2 Employee 1 | Finance | | 170 | | | |
3 Employee 2 | Risk | Finance | 170 | | | |
4 Employee 3 | Finance | | 170 | | | |
5 Employee 4 | IT | Risk | 170 | | | |
6 Employee 5 | IT | Finance | 170 | | | |
I want to use columns E:G as a supply calculator per team. Therefore, the formula in cell E2 would be "=IF(B2=E1,D2,0)" and copied along the row, returning the 170 days under Finance and 0 under the rest.
The issue lies where an employee divides his time between two different teams. As you can see, some employees can work for 2 different teams (Employee 2 works for both Finance and Risk, for example). The formula in E3 would therefore need to be some kind of IF AND, where if a value is present in the Team 2 column (C), the value in the Days column (D) would be divided by two and split across the relevent team columns.
I've tried a few options, IF AND, nested IFS etc but cant seem to get the syntax correct. Any help greatly appreciated.
=IF(ISNUMBER(MATCH(E$1,$B2:$C2,0)),$D2/COUNTA($B2:$C2),0)
You actually want OR and COUNTA:
=IF(OR($B2=E$1,$C2=E$1),$D2/COUNTA($B2:$C2),0)
I have 2 price lists from 2 different companies but there are some many similar item numbers, is there a code to merge the pricelists into one? below example of what I have.
A-Pricelist
Item | Product | Price
382101 | Truck | 130$
212012 | car | 80$
B-Pricelist
Item | Product | Price
111011 | Airplane | 500$
382101 | truck | 50$
Expected result
Item | Product | A Price | B Price
382101 | Truck | 50$ | 130$
212012 | car | 80$ | -
111011 | Airplane | - |500$
I have seen it is done by Vlookup, but it is just not working for me, thanks.
So, vlookup will work fine, I would think about how to control the list of unique values using a dropdown...
But here is an example, updated to deal with missing prices:
I have a table like this in excel
ID | NAME | JOB | PRICE
1 | alex | Java | 100
1 | alex | C++ | 100
1 | alex | PHP | 500
2 | road | Android | 400
2 | road | Ruby | 400
3 | brit | Java | 200
3 | brit | PHP | 500
3 | brit | C | 100
3 | brit | DotNet | 300
I need output in following format
ID | NAME | JOB | PRICE
1 | alex | Java,C++,PHP | 700
2 | road | Android,Ruby | 800
3 | brit | Java, PHP, C, DotNet | 1100
so i use Microsoft Query to generate this output using the following query
Select ID, NAME , GROUP_CONCAT(JOB) ,Sum(PRICE) from Table Group By ID;
but it keep to show me error .. any suggestion
Possibly the closest you can get with SQL is the crosstab query which is available in the Jet/ACE SQL dialect. Jet/ACE is a set of Windows .dll files used for ODBC/OLEDB connections of MS Access databases and Excel spreadsheets. Do note Jet/ACE imposes a maximum limit of 255 columns.
Specifically, below calculates a running count of alphabetically ordered jobs (taking the max of repeat values) and then pivots from that source:
TRANSFORM Max(main.Job) As MaxOfJob
SELECT main.ID, main.[Name], Sum(main.PRICE) AS SumOfPrice
FROM (
SELECT i.*, (SELECT Count(*) FROM [Sheet1$] sub
WHERE sub.ID = i.ID AND sub.JOB <= i.JOB) As RunCount
FROM [Sheet1$] i
) AS main
GROUP BY main.ID, main.[Name]
PIVOT main.RunCount;
-- ID Name SumOfPrice 1 2 3 4
-- 1 alex 700 C++ Java PHP
-- 2 road 800 Android Ruby
-- 3 brit 1100 C DotNet Java PHP
Once you have a completed resultset, concatenate all the numbered column cells into the comma-separated JOB column with Excel's CONCATENATE() or loop through each column cell with VBA.
The way you want your table to look like includes a "Combined field", which is frowned upon in database design. You're initial design is correct, in the sense that each language takes up 1 entry in the table.
Hi I am using Magento and an extension called matrix rates, they use .CSV files to store the data for the post codes saying what post code has what delivery charge. The problem I have got is that it only picks the smallest delivery charge for every single postcode when it should look at the rate for the post code first and then if there isn't one pick the flat rate. I was just wondering if anybody has any ideas.
My excel sheet is like this>>
Country | Region/State | City | Zip/Postal Code From |Zip/Postal Code To | Weight From | Weight To | Shipping Price | Delivery Type
GBR | * | - | - | 0 | 9999 | 9999 | Websales Shipping (WS01)
GBR | * | - | - | AB37% | 0 | 9999 | 65 | Websales Shipping (WS01)
Without more details, your pseudo-code (or, pseudo-formula) could look like this:
=if(
vlookup([postCode], [PostCodeShipRateTable], [rateColumn]) >0,
[postcodeRate],
[flatRate]
)
[flatRate] could also be a vlookup to another rate table if nec.