I am basically trying to get the top 10 claims by order of fee for all countries. The ranking is simple to do and i already have the rank built.
=Rank([Estimated Loss Amount Home Currency];([Claim ID]);Top)
But how do i apply that so it does the top 10 for each country?
At the moment i have it set up with a break on the country so it ranks the claims within each country. So for example Australia has 21 claims showing (which is all of them and ranks them 1 - 21). When I apply my rank variable as a filter for the top 10, it does it on my whole data set not each country so i end up with top 10 in just Australia and lose the rest of the countries.
I have recreated it in SQL which is easy to do, just cant fathom the logic round it in Webi.
Thank you.
The technical documentation indicates how to do this: Most of the below is a direct copy from that technical documentation.
Syntax
int Rank(measure;[ranking_dims][;Top|Bottom][;(reset_dims)])
Input
+--------------+-----------------------------------------+----------------+---------------------+
| Parameter | Description | Type | Required |
+--------------+-----------------------------------------+----------------+---------------------+
| measure | The measure to be ranked | Measure | Yes |
| ranking_dims | The dimensions used to rank the measure | Dimension list | No |
| Top|Bottom | Sets the ranking order: | Keyword | No (Top is default) |
| | | | |
| | Top - descending | | |
| | Bottom - ascending | | |
| | | | |
| reset_dims | The dimensions that reset the ranking | Dimension list | No |
+--------------+-----------------------------------------+----------------+---------------------+
Notes
The function uses the default calculation context to calculate the ranking if you do not specify ranking dimensions.
You must always place dimensions in parentheses even if there is only one dimension in the list of ranking or reset dimensions.
When you specify a set of ranking or reset dimensions you must separate them with semi-colons.
By default the ranking is reset over a section or block break.
So in your case:
=Rank([Estimated Loss Amount Home Currency];([Claim ID]);Top;([Country]))
Example
In the following table the rank is given by Rank([Revenue];([Country];[Year]);([Country])). The rank is reset on the Country dimension.
+---------+--------+---------+------+
| Country | Year | Revenue | Rank |
+---------+--------+---------+------+
| France | FY1998 | 295,940 | 1 |
| France | FY1999 | 280,310 | 2 |
| France | FY2000 | 259,170 | 3 |
| US | FY1998 | 767,614 | 3 |
| US | FY1999 | 826,930 | 2 |
| US | FY2000 | 856,560 | 1 |
+---------+--------+---------+------+
Related
I would like to ask for a help.I use MySQL 5.7 and I have a Bill of Materials table called BOM.
I have many columns there which I will add later to the query, but for this questionID, Name, ParentID and Quantity is important. I would like to add a calculated column totalQty to my table that will multiply children quantities with parent quantities up to the top level. here is an example of what I want to achive:
+-------+------+------+----------+----------+--+
| ID | Name | Qty | ParentID | TotalQty | |
+-------+------+------+----------+----------+--+
| 1 | A | 1 | 0 | 1 | |
| 1.1 | AA | 2 | 1 | 2 | |
| 1.1.1 | AAA | 1 | 1.1 | 2 | |
| 1.2 | AB | 5 | 1 | 5 | |
| 1.2.1 | ABA | 2 | 1.2 | 10 | |
| 2 | B | 3 | 0 | 3 | |
| 2.1 | BA | 2 | 2 | 6 | |
+-------+------+------+----------+----------+--+
I need this to create a list of materials used per project, so I will multiply totalQTY with unit mass and unit length to get total mass and total length of part. Then I will group and aggregate them by material type.
I have searched the forums, and I have found out that I need to use Common table expressions (CTE) for this. But I have found no explanation in plain english on how to do it for my case.
Thank you very much for any help or hint how to understand the concept.
I am creating an APP, similar to OLX. From server end I'm using Laravel's Lumen. My problem is that I cannot figure out how to store assigned attributes to ads. Of course I know there are maaaany ways, but I need to find the best way to make it very efficient.
I've got two ideas, and both of them seems to be bad ;)
1. Creating separete row for each attribute assigned to an ad like:
| id | ad_id | attribute_id | value |
| 1 | 1 | 12 | new |
| 2 | 1 | 17 | wooden|
| 3 | 1 | 123 | 114 |
but it seems to lead to problems in the future when there will be millions assigned attributes
2. on the other hand creating serialized values is not easily searchable, while trying to filter ads by attributes.
| id | ad_id | attribute_value |
| 1 | 1 |a:3:{i:0;a:1:{i:12;s:3:"new";}i:1;a:1:{i:17;s:6:"wooden";}i:2;a:1:{i:123;s:3:"114";}}|
Any ideas?
EDIT:
I've decided not to use any multivalued attributes, but I'll try to make clear the rest of my problems:
After following some advises I divided all the attributes into 3 groups:
1. Not searchable, serialized, stored directly in ads table - seems to be the best choice for values that I just need to display.
2. with predefined selection choices using 3 tables:
Attributes:
id | name | slug | category | type | required | purpose
1 | Color | color | 2 | select | true | both
Attribute values:
id | attribute_id | value | slug
1 | 23 | Blue | blue
2 | 23 | Red | red
3 | 23 | Green | green
Attribute relations:
id | attribute_val_id | ad_id
1 | 24 | 54
3. And third, attribute values entered by user:
Attributes:
id | name | slug | category | type | required | purpose
2 | Size | size | 234 | input | true | both
Custom attributes:
id | attribute_id | value | ad_id
1 | 24 | 2052 | 54
Is it the best approach?
I have a database with basically 3 tables:
accounts <-- operations --> orders
I would like to allow transactions of money from n accounts to m accounts.
For instance, let's consider a transaction of $11 from Alice and Sophia to Bob ans Joe:
| Sender | Receiver |
| ------ | -------- | ------ |
| 1 | | Alice |
| 10 | | Sophia |
| | 6 | Bob |
| | 5 | Joe |
What I would like to ensure is that, the sum of the moved amount is always equal to zero (in this example: (1 + 10) - (6 + 5) == 0).
In this example, I would have 4 rows inside the operations table.
Until now, I did some control using an programming language such as PHP to ensure that the sum is always zero. But I would really prefer to ensure it on the physical layer, with MySQL.
Also, if possible, I would prefer to DRY the amount which is equal between the sender and the receiver sides. Right now, I don't think that my database structure is normalized. Do you think m
Thank you for your feedback/advice!
Edit
There is what the SQL tables look like:
____________
| accounts |
| -------- |
| id |
------------
______________
| operations |
| ---------- |
| id |
| account_id |
| order_id |
| amount | <- can be positive or negative
--------------
__________
| orders |
| ------ |
| id |
----------
Unique identifier across multiple tables?
Using MySQL, I'm trying to associate products with a purchase order.
Those products can become from different tables probably with different schema's.
I cant associate because of the identity of each product by schema, not by all kinds of products.
Cellphone
+-----+--------+---------+-------+----------+-------+
| id | brand | version | color | capacity | price |
+-----+--------+---------+-------+----------+-------+
| 1 | iphone | 5s | black | 16 | 9500 |
| 2 | iphone | 5s | white | 32 | 10000 |
| 3 | iphone | 5s | blue | 32 | 10000 |
+-----+--------+---------+-------+----------+-------+
Course
+-----+-----------+------------+-------+
| id | topic | idschedule | price |
+-----+-----------+------------+-------+
| 1 | Photoshop | 1 | 9500 |
| 2 | HTML5 | 2 | 10000 |
| 3 | CSS3 | 3 | 10000 |
+-----+-----------+------------+-------+
I've made a table Product, that together with a product identity, produce an unique identifier.
Product
+-----+-----------+
| id | Schema |
+-----+-----------+
| 1 | Cellphone |
| 2 | Course |
+-----+-----------+
ProductEspecification
+-----+-----------+------------------+----------+------------+
| id | idproduct | idespecification | quantity | idpurchase |
+-----+-----------+------------------+----------+------------+
| 1 | 1 | 1 | 10 | 1 |=> 10 iphones
| 2 | 2 | 3 | 1 | 1 |=> 1 CSS3 course
+-----+-----------+------------------+----------+------------+
Is there a better approach?
You need to use abstraction and Table Inheritance.
An abstract thing you sell (good, service, etc) is called a Product.
An abstract physical good you sell is called a Good. Good inherits Product.
An abstract service you offer is called a Service. Service inherits Product.
Cellphone inherits Good.
Course inherits Service.
I am filtering a tablix and then grouping both rows (total of 3) and columns (total of 2), with no detail section. One row only has an applicable value for one of the grouped columns. The group by places all of the values in the correct cell. However, if I add an indicator, the row without an applicable value for the column inherits data from another row. Adding the field that the indicator is based on does not make this change. This row (and others that are working correctly) has a null value for the indicator in the first column, IE it shouldn't show up.
Dataset:
+---------+---------------+-----------+---------+
| Family | Description | Value |Indicator|
+---------+---------------+-----------+---------+
| A | Something | 5 | 2 |
| A | Another | 2 | 1 |
| B | Yearly Plans | 63 | null |
| B | Weekly Plans | 4 | 2 |
| B | Yearly Qual | .4 | 1 |
| B | Weekly Qual | .2 | 1 |
| B | Purchased % | .76 | null |
+---------+---------------+-----------+---------+
Filter tablix for Family = B
Row Group: =iif(Field!Description.Value like "Plans","Plans",iif(Field!Description.Value like "Qual","Qualifying",Field!Description.Value))
Column Group: iif(Field!Description.Value like "Yearly*","YTD","Weekly")
Result without indicators:
+---------------+------------+----------+
| Description | Weekly | YTD |
+---------------+------------+----------+
| Qualifying | .2 | .4 |
| Plans | 4 | 63 |
| Purchased % | .76 | |
+---------------+------------+----------+
Result with indicators (Based on indicator field):
+---------------+--------+---+--------+---+
| Description | Weekly | | YTD | |
+---------------+--------+---+--------+---+
| Qualifying | .2 | - | .4 | - |
| Plans | 4 | + | 63 | |
| Purchased % | .76 | | .4 | - |
+---------------+------------+--------+---+
What it SHOULD be:
+---------------+--------+---+--------+---+
| Description | Weekly | | YTD | |
+---------------+--------+---+--------+---+
| Qualifying | .2 | - | .4 | - |
| Plans | 4 | + | 63 | |
| Purchased % | .76 | | | |
+---------------+------------+--------+---+
I have patched the current problem by unioning in a Yearly Purchased % row with null values, but there must be something else going one. Is there something in how indicator's behave that would add values that aren't part of a group?
I realized the same thing, could it be a bug in SSRS indicators, as workaround, you can write an expression inside the cell to check against another cell and investigate if there is data then show the value inside the cell, if not then write nothing.
like: =iif(count(Fields!Field1.Value)>1,"",Fields!Field2.Value)