Reporting Services: how to apply interactive sort for matrix columns? - sorting

I need to apply interactive soring for matrix columns, which contain aggregated data.
The report is counting products sold in different places:
Product A Product B Product C
---------------------------------------------------------------
Country 1 5 10 4
City A 3 0 3
City B 2 10 1
---------------------------------------------------------------
Country 2 10 5 5
City C 2 4 2
City D 8 1 3
After descending sorting on "Product A" the table rows should be sorted by "Product A" sales in country, and also by sales in city:
Product A Product B Product C
---------------------------------------------------------------
Country 2 10 5 5
City D 8 1 3
City C 2 4 2
---------------------------------------------------------------
Country 1 5 10 4
City A 3 0 3
City B 2 10 1
The matrix scheme looks like this:
| [Product]
[Country] | [City] | [Count(Product)]

Interactive sort is not supported in matrix.
A workaround could be the one below:
Create a sort by parameter with the values:
Label Value
Country ASC, City ASC 1
Country DESC, City ASC 2
Country ASC, City DESC 3
Country DESC, City DESC 4
Then in the country create two sorting expressions:
=Iif(Parameters!SortBy.Value = 1 OR Parameters!SortBy.Value = 3,Fields!country.Value,"")
ASCENDING sort
=Iif(Parameters!SortBy.Value = 2 OR Parameters!SortBy.Value = 4,Fields!country.Value,"")
DESCENDING sort
Do the same for city:
=Iif(Parameters!SortBy.Value = 1 OR Parameters!SortBy.Value = 2,Fields!city.Value,"")
ASCENDING sort
=Iif(Parameters!SortBy.Value = 3 OR Parameters!SortBy.Value = 4,Fields!city.Value,"")
DESCENDING sort

Related

Laravel Query Builder Join 3 table and count result

I'm hanging in this, and , hope someone can bring me out this task. i have 4 table called "LOCATIONS","COUNTRIES","REGIONS"AND "DISTRICT".
LOCATIONS
id
name
1
country
2
region
3
district
id
name
COUNTRIES
id
location_id
country
1
1
India
2
1
Italy
3
1
Philippines
4
1
Japan
5
1
Taiwan
6
1
Canada
7
1
USA
8
1
Russia
REGIONS
id
location_id
country_id
region
1
2
2
Region1
2
2
2
Region3
3
2
3
Region8
DISTRICT
id
location_id
region_id
district
1
3
1
district 1
2
3
1
district 3
3
3
1
district 8
Desired Output
COUNTRY
REGION
DISTRICT
India
0
0
Italy
2
0
Philippines
1
3
Japan
0
0
Taiwan
0
0
Canada
0
0
USA
0
0
Russia
0
0
MY QUERY is working but groupby is not working when i apply and only 2 country will appear.
$getcountry = LocationModel::join('location_country as country','country.location_id','locations.id')
->join('locations_region','locations_region.country_id','=','country.id')
->select([
'locations.*',
'country.*',
'locations_region.*'
])
->orderBy('country.country')
->paginate(10);

Multiple sorting conditions in DolphinDB

Suppose I have a table as follows:
id=`A`B`A`B`B`B`A
item= 10 1 1 3 5 10 6
t=table(id,item)
id item
-- ----
A 10
B 1
A 1
B 3
B 5
B 10
A 6
For example, I want to sort the table with two conditions: first, by the most commonly occurring item in column item, then by the highest number in column item.
How can I sort like this:
id item
--- ----
A 10
B 10
A 1
B 1
A 6
B 5
B 3
Is there any way to go about this? Thanks!
Try this:
t1=table(id,item);
update t1 set count=count(item) context by item;
select * from t1 order by count desc, item desc;

DAX measure: disctinct count per group

Excel - Power Pivot
I am trying to create a measure to calculate a disctinct count (or a sum of a disctinct count) of a column - grouped by a second column.
Based on the column "lot" an the column "sku", I want to calculate the column "count_distinct_sku_by_lot". Column "sqm" is not relevant.
Which DAX code I could use?
(picture of data added)
lot sku sqm count_distinct_sku_by_lot
lot1 sku1 1 1
lot2 sku2 2 2
lot2 sku2 3 2
lot2 sku3 4 2
lot3 sku4 5 3
lot3 sku4 6 3
lot3 sku5 7 3
lot3 sku5 8 3
lot3 sku6 9 3
lot4 sku7 11 1
You can create a calculated Column :
DistinctCount =
VAR VrCurrentRow = [lot]
RETURN
CALCULATE(
DISTINCTCOUNT(Sheet1[sku]);
FILTER(
Sheet1;
Sheet1[lot] = VrCurrentRow
)
)
Result :

Getting Sum of Multiple Columns and summing up values for the same id from a list

I have a list which returns.
Grade Col1 Col2 Col3 Col4
t1 2 1 3 2
t2 2 5 1 5
t1 2 6 4 4
First, i need to add the values in each row for the corresponding Grade so that , i would have
Grade Sum(Sum of the 4 columns)
t1 8
t2 13
t1 16
and finally my result should be like:
Grade Total
t1 8+16 = 24
t2 13
I'm a newbie to Linq., can someone suggest me the approach using Linq, for returning this result.??
Thanks
Following LINQ query will group all rows by Grade and then produce sum of columns for each grade:
var query = from r in list
group r by r.Grade into g
select new {
Grade = g.Key,
Total = g.Sum(x => x.Col1 + x.Col2 + x.Col3 + x.Col4)
};

Fix numbering of many item groups in table

I have a table with these columns
create table demo (
ID integer not null,
INDEX integer not null,
DATA varchar2(10)
)
Example data:
ID INDEX DATA
1 1 A
1 3 B
2 1 C
2 1 D
2 5 E
I want:
ID INDEX DATA
1 1 A
1 2 B -- 3 -> 2
2 1 C or D -- 1 -> 1 or 2
2 2 D or C -- 1 -> 2 or 1
2 3 E -- 5 -> 3 (closing the gap)
Is there a way to renumber the INDEX per ID using a single SQL update? Note that the order of items should be preserved (i.e. the item "E" should still be after the items "C" and "D" but the order of "C" and "D" doesn't really matter.
The goal is to be able to create a primary key over ID and INDEX.
If that matters, I'm on Oracle 10g.
MERGE
INTO demo d
USING (
SELECT rowid AS rid, ROW_NUMBER() OVER (PARTITION BY id ORDER BY index) AS rn
FROM demo
) d2
ON (d.rowid = d2.rid)
WHEN MATCHED THEN
UPDATE
SET index = rn

Resources