Equal operator will not work on positive numbers SSRS - reporting-services

I am trying to return data based upon an IIF statement in table within SSRS. When I run this statement it returns as expected:
: =iif(Fields!WKBUCKET.Value =-1,1,0)
but if I run this
=iif(Fields!WKBUCKET.Value =0,1,0)
it won't return any data. I know that I have data with where values are up to a positive 4 and it will not return anything. I am sure it is something easy I am missing.
Here is some data
|NEED_QTY| BKTMOD|RQCOM| ITDSC| WEEKOF| WKBUCKET|
150.000 -1 205701 2 FACER BLADE 1.38LG 2020-12-14 00:00:00.000 -1
86.000 1 205701 2 FACER BLADE 1.38LG 2020-12-28 00:00:00.000 1
132.000 2 205701 2 FACER BLADE 1.38LG 2021-01-04 00:00:00.000 2

Related

what is the correct way to select the highest value from column not primary key

I have a table (report) consist of several records and one of them about int values (column) I am trying to get the highest number of the fall_value column the id only primary key, the table as following:
id (P)
fall_value
date
3
1.2
2021-01-29
4
1.5
2021-01-30
5
1.6
2021-01-30
6
1
2021-01-31
7
5
2021-01-31
8
1.5
2021-01-31
9
1.5
2021-01-31
10
14
2021-01-31
11
15
2021-01-31
expected result: 15
I have tried the following inquiry:
SELECT max(fall_value) from report;
I got an unexpected result: 5
and also I got a message saying:
Current selection does not contain a unique column. Grid edit, checkbox, Edit, Copy and Delete features are not available
It sounds like fall_value is a string, not a number, and the string "5" is indeed greater than the string "15".
Try converting to a number. A convenient way is to use implicit conversion:
SELECT max(fall_value + 0)
FROM report;

Exclude the combination of 2 columns only from my query

Sounds simple but I couldn't find the solution for it.
I have a table with 3 columns. Account, Amount, Date.
I want to get all entries except the ones of one specific account with negative amount. But I still want to get the entries of this account if amount value is positive.
So with this query I'm also not getting the entries from account1 with a positive amount.
select * from table where (account!='account1' AND amount<='0') AND date='2020-05-01'
You can do this using WHERE NOT in your statement.
Example schema:
Account Amount Date
=====================================
1 Ben 200 2020-10-10
2 Frank 200 2020-10-10
3 Ben -300 2020-10-12
4 Ben 10 2020-10-16
5 Mary 2000 2020-10-16
6 Frank -200 2020-10-18
7 Ben -10 2020-10-18
8 Ben 0 2020-10-20
Now if you build your query like this
SELECT * FROM t1 WHERE NOT (account='Ben' AND amount<0);
you should get what you want (all records except the 3rd and 7th).
Edit: if you really only want to exclude records with negative amounts, you need to do < rather than <= as you did in your example above. Depends on whether you want row 8 to be included in the result or not.

Joining together consecutive date

I have versions of the value that need to be combined. Records with other identifiers may also appear in the input table.
How i can do this in MySQL?
Input
ID Prev Value StartDate Finishdate
1140004 0 0 2019-11-01 00:00:00.000 2019-11-09 23:59:00.000
1140004 0 1 2019-11-10 00:00:00.000 2019-11-14 23:59:00.000
1140004 1 1 2019-11-15 00:00:00.000 2019-11-30 23:59:00.000
Expected
ID Prev Value StartDate FinishDate
1140004 0 1 2019-11-10 00:00:00.000 2019-11-30 23:59:00.000
Please add more details about your expected result as you will need to perform some sort of aggregation/calculation on the columns which are not ID to get to the one row result you are expecting (as this will of course need to be grouped by ID).
Below, for example, for every Id we get the sum of value, the min StartDate and the max FinishDate. What sort of aggregation you do for each column depends on your use case of course so this is just an example.
You can play around with this example here.
select Id,
sum(Value) as "Sum Value",
min(StartDate) as "Min StartDate",
max(FinishDate) as "Max FinishDate"
from data
group by Id

Mdx produces repeated values for a measure and across measures

The MDX query below is giving me repeated measure values as shown in the result below the query. Sometimes it give me save valuea across different measures.
SELECT
NON EMPTY {[Measures].[Amount],} ON COLUMNS,
NON EMPTY {
( [Date_Time].[Date].[Date].ALLMEMBERS * [Date_Time].[Working Day].[Working Day].ALLMEMBERS )
}
DIMENSION PROPERTIES
MEMBER_CAPTION,
MEMBER_UNIQUE_NAME
ON ROWS
FROM [DDS]
where {[Date_Time].[Year].&[2010-01-01T00:00:00] }
Date working day Amount
2010-01-01 00:00:00.000 1 19582
2010-01-02 00:00:00.000 0 19582
2010-01-03 00:00:00.000 0 19582
2010-01-04 00:00:00.000 1 19582
2010-01-05 00:00:00.000 1 19582
2010-01-06 00:00:00.000 1 19582
2010-01-07 00:00:00.000 1 19582
How can I rectify these issues?
You would get results like this if you have not specified a relationship between the date and the measure group that contains your measure. You would need to go into the dimension usage tab for your cube and fix this.

MySQL: Matching inexact values using "ON"

I'm way out of my league here...
I have a mapping table (table1) to assign particular values (value) to a whole number (map_nu). My second table (table2), is a collection of averages (avg) for each user (user_id).
(I couldn't figure out how to properly make a markdown table, please feel free to edit!)
table1: table2:
(value)(Map_nu) (user_id)(avg)
---- -----
1 1 1 1.111
1.045 2 2 1.2
1.09 3 3 1.33333
1.135 4 4 1
1.18 5 5 1.389
1.225 6 6 1.42
1.27 7 7 1.07
1.315 8
1.36 9
1.405 10
The value Map_nu is a special number that each user gets assigned according to their average. I need to find a way to match the averages from table2 to the closest value in table1. I only need to match to the 2 digit past the decimal, so I've added the Truncated function
SELECT table2.user_id, map_nu
FROM `table1`
JOIN table2 ON TRUNCATE(table1.value,2)=TRUNCATE(table2.avg,2)
I still miss the values that don't match the averages exactly. Is there a way to pick the nearest truncated value or even to round to the second decimal? Rounding up/down wont matter as long as its applied to all values the same.
I am trying to have the following result (if rounded up):
(user_id)(Map_nu)
----
1 4
2 6
3 6
4 1
5 10
6 11
7 3
Thanks!
i think you might have to do this in 2 separate queries. there is no 'nearest' operator in sql, so you can either calculate it in your software, or you could use
select map_nu from table1 ORDER BY abs(value - $avg) LIMIT 1
inside a loop. however, that cannot be used as a join function as it requires the ORDER and LIMIT which are not valid as joins.
another way of looking at it is it seems that your map_nu and value are deterministic in relation to each other - value = 1 + ((map_nu - 1) * 0.045) - so maybe you could make use of that fact and calculate an integer based on that equation? assuming that relationship holds true for all values of map_nu.
This is an awkward database design. What is the data representing and what are you trying to solve? There might be a better way.
Maybe do something like...
SELECT a.user_id, b.map_nu, abs(a.avg - b.value)
FROM
table2 a
join table1 b
left join table1 c on abs(a.avg - b.value) > abs(a.avg - c.value)
where c.value is null
order by a.user_id
Doesn't actually produce the same output as the one you were expecting for (doesn't do any rounding). Though you should be able to tweak it from there. Above query will produce the output below (w/ data you've provided):
user_id map_nu abs(a.avg - b.value)
------- ------ --------------------
1 3 0.0209999999999999
2 5 0.02
3 8 0.01833
4 1 0
5 10 0.016
6 10 0.0149999999999999
7 3 0.02
Beware though if you're dealing with large tables. Evaluate the explain of the above query if it'll be practical to run it within MySQL or if better to be done outside it.
Note 2: Will produce duplicate rows if there are avg values that are equi-distant to value values within table1 (Ex. if value for map_nu's 11 and 12 are 2 and 3 and someone get's an avg of 2.5). Your question doesn't really specify what to do for that so you might want to take that into account.
Its taking a little extra work, but I figure the easiest way to get my results will be to map all values to the second decimal place in table1:
1 1
1.01 1
1.02 1
1.03 1
1.04 1
1.05 2
1.06 2
1.07 2
1.08 2
1.09 3
1.1 3
1.11 3
1.12 3
1.13 3
1.14 4
...
Thanks for the suggestions! Sorry I couldn't present the question more clear.