SSRS problem gruping RowWise and perform Sum or Dfference - reporting-services

i'm working on a SSRS Report whose structre is the following:
ID
CostCode
Amount
1
79
$ 100,00
1
80
$ 80,00
2
79
$ 850,00
2
79
$ 500,00
3
79
$ 200,00
3
79
$ 265,00
3
79
$ 478,00
4
79
$ 665,00
4
79
$ 130,00
4
79
$ 380,00
4
80
$ 50,00
4
80
$ 100,00
Basically I need to group by ID, and
if all codes for that ID are 79, sum the amount
if there is one (or more) row with code 80, I need to sum the amount for the rows with code 79 and then subtract the amount for the rows with code 80
The output should be like this (the CostCode column can be left empty):
ID
CostCode
Amount
1
-
$ 20,00
2
-
$ 1350,00
3
-
$ 943,00
4
-
$ 1025,00
Thanks in advance for the help :)

That should be simple to do... Something like this...
=SUM(Fields!Amount.Value * (IIF(Fields!CostCode.Value = 80, -1, 1)))
All we do here is check if the costcode field is 80 and if so multiple the Amount by -1, if not we multiply it by 1.

Related

MySQL: Get count for each range

There is mysql Ver 8.0.18 value_table as:
value count
1 3
11 1
12 2
22 5
31 1
34 3
35 1
40 3
46 7
What is query to get a total count for each dozen (1-10 - first dozen,11-20 - second , etc..)
as:
1 3
2 3
3 5
4 8
5 7
Query should be flexible, so when some records added to value_table , for example
51 2
62 3
so, it is not necessary to change a query by adding new range (51-60 - 6-th dozen, etc.)
I think you just want division and aggregation:
select min(value), sum(count)
from t
group by floor(value / 10);
To be honest, I'm not sure if the first column should be min(value) or floor(value / 10) + 1.

Mysql Parsing logic on Multiple rows

I have parsing Queries with below references
link1 - SET and Select Query combine Run in a Single MySql Query to pass result in pentaho
link2
Input will be shown in below Col1 showing ,In #input in the above reference link i am considering only 1 records and applying parsing logic for each cell , but issue is with multiple rows (n rows) and combining result with parsing logic.
Col1
--------------
22:4,33:4
33:6,89:7,69:2,63:2
78:6
blank record
22:6,63:1
I want to create single Query for same as in reference link i asked for.
Expected Output
xyz count
------------
22 10
33 10
89 7
69 2
63 3
78 6
I tried solutions Passing values with this conditions
where condition pass 1 by 1 col1 in (my query)
MAX (col1)
group_concat
but i am not getting expected output to fit this all things in a single query.
I finally found solution for my question. and group_concat worked for this
#input= (select group_concat(Col1) from (select Col1 from table limit 10)s);
group_concat will merge all the rows of Col1 into comma seperated string
22:4,33:4,33:6,89:7,69:2,63:2,78:6,blank record,22:6,63:1
as we have now single string we can apply same logic as shown in link 1
we can replace blank record with REPLACE command and neglect it.
Output after using logic from link1 result
xyz count
------------
22 4
33 4
33 6
89 7
69 2
63 2
78 6
22 6
63 1
Just use Group by
select xyz,sum(count) from (select link1 output)s group by xyz;
will give you Final Output
xyz count
------------
22 10
33 10
89 7
69 2
63 3
78 6

CSV, convert multiple rows in to comma delimited list grouped by another column's value

I have a CSV file with two columns. Column 1 contains a group ID and Column 2 contains an item ID.
Here's some sample data (copied out of excel)
- 5 154
- 5 220
- 5 332
- 5 93
- 5 142
- 5 471
- 5 164
- 5 362
- 5 447
- 5 1697
- 5 170
- 6 173
- 6 246
- 6 890
- 6 321
- 6 421
- 6 1106
- 6 5
- 6 253
- 6 230
- 6 551
- 8 2155
- 8 2212
- 8 2205
- 8 2211
- 8 2165
- 8 2202
- 8 1734
- 8 2166
- 8 2129
I need to reformat this so that I have just one row for each group ID and Column 2 contains a comma delimited list of item IDs.
So it should look something like this
-5 154,220,332,93,142,471,164362,447,1697,170
-6 173,246,890,321,421,1106,5,253,230,551
-8 2155,2212,2205,2211,2165,2202,1734,2166,2129
I'm happy to import the CSV in to Excel / Numbers in order to reformat. Or even in to a temp MySQL database if a SELECT query can achieve this.
Thank you for your help!
I feel something like this is best solved with R and reshape.
But here you go in Excel:
assuming
group keys in column A
item keys in column B
unique group keys in column D (I guess you can do this manually)
enter into E2:
=INDEX($B:$B,SMALL(IF($A$2:$A$50=$D2,ROW($A$2:$A$50),""),COLUMN()-COLUMN($D2)))
and press CTRL+SHIFT+ENTER to enter it as an array formula. Now you can copy cell E2 to F2:P2 and E3:P4.
result:

dlookup function in access

I'm first time trying to use dlookup function in access as below but I get blank output.
select dlookup ("quantity","test","series > 2000") from test
This is test table
id series quantity
1 1000 25
2 2000 33
3 3000 44
4 4000 55
5 5000 66
6 6000 77
I thought the above query will display all records from the table below which has series more than 2000 i.e. as below but it displays blank result.
id series quantity
3 3000 44
4 4000 55
5 5000 66
6 6000 77
I'm not sure if my syntax is incorrect or anything else. I already double checked my syntax from various sources though.
DLookup() returns a single value, which is not what I think you want. Just put your selection constraint in the WHERE clause.
SELECT id, series, quantity
FROM test
WHERE series > 2000;

Querying a table to get values based on no of digits of a parameter?

Considering the following table
I have a large table from which I can query to get the following table
type no of times type occurs
101 450
102 562
103 245
111 25
112 28
113 21
Now suppose I wanted to get a table which shows me the sum of no of times type occurs
for type starting with 1 then starting with 10,11,12,13.......19 then starting with 2, 20,21, 22, 23...29 and so on.
Something like this
1 1331 10 1257
11 74
12 ..
13 ..
.. ..
2 ... 20 ..
21 ..
Hope I am clear
Thanks
You really have two different queries:
SELECT [type]\100 AS TypePart, Count(t.type) AS CountOftype
FROM t
GROUP BY [type]\100;
And:
SELECT [type]\100 AS TypePart, [type] Mod 100 AS TypeEnd,
Count(t.type) AS CountOftype
FROM t
GROUP BY [type]\100, [type] Mod 100;
Where t is the name of the table.
Here on the first query i am getting something like this
utypPart CountOftype
1 29
2 42
3 46
4 50
5 26
6 45
7 33
9 1
it is giving me how many utyp are starting with 1 2 and so on
but whai i want is the sum of no of times those types occur for the utyp .