Fixed values not accepted in SSRS - reporting-services

I created the above query for a time range, and I am attempting to add it to the parameters
Although this is a fixed value, I am unable to get the query to accept the fixed value.
Is there any other way to approach this?

I think you are approaching this incorrectly. As far as I know you cannot use the results of a query to populate a parameter value like that.
If the below does not work, then I would edit your question, show a sample of the data you are working with, the parameter labels you want to show and then the expected outcome.
At the moment your parameter value will just be a text string that looks like a t-sql query
You probably just need to edit your dataset query and parameter values.
For example. Set you parameters values to
Label
Value
Shift 1
1
Shift 2
2
Shift 3
3
Then your dataset query would look something like
SELECT * FROM myTable
WHERE CAST(myDateTimeColumn AS Time) BETWEEN
CASE #Shift
WHEN 1 THEN CAST('21:00:00' AS Time)
WHEN 2 THEN CAST('22:00:00' AS Time)
WHEN 3 THEN CAST('23:00:00' AS Time)
END
AND
CASE #Shift
WHEN 1 THEN CAST('21:59:59' AS Time)
WHEN 2 THEN CAST('22:59:59' AS Time)
WHEN 3 THEN CAST('23:59:59' AS Time)
END
This won't be perfect as it would miss anything less than a second before a new hour but should get you on the right track.
note: This is also untested as it's done from memory

Related

Migrating Measures and calculated columns from Tableau to PowerBi

Stuck at a specific measure calculation which looks like this in tableau
1.) zn(COUNTD(if not isnull([Order_number]) then [Order_number] END)).
I tried using isblank dax function but it is not working as i expected it to be.
How will the same measure be written in Powerbi using DAX?
Problem 2
Simultaneously, not able to get the output for a particular calculated column in powerbi for which the tableau query to derive that particular column looks like this:
2.) zn(IF CONTAINS([Record Type],"High") and datename('weekday',[Activity Date]) = 'Sunday' AND [Location] = '08520' THEN 7 ELSEIF CONTAINS([Record Type],"Junior") and datename('weekday',[Activity Date]) = 'Sunday' AND [Location] = '8520' THEN 7 end
I re created the above by Creating a custom column named it as Day Name deriving day name from the date column and Wrote an equivalent query in Powerbi query editor to create a custom column, query mentioned below. Even though there is no syntax error, it is giving 0 for all the rows in that particular calculated column.
slots= if([RECORD_TYPE]="high" and [Day Name]="Sunday" and [LOCATION]=08520) then 7 else
if([RECORD_TYPE]="Outbound" and [Day Name]="Sunday" and [LOCATION]=3109) then 7 else 0
Any kind of lead or help will be much appreciated.
Thanks in advance
For 1st problem:
zn(COUNTD(if not isnull([Order_number]) then [Order_number] END))
So, If i break this query basically, zn is a function used in tableau to convert all the null values to zero and as countd implies to the entire if statement above.
I was able to write an equivalent dax query for it mentioned below, if anyone out there can tell me or verify if it is correct or not, I'll be really thankful.
IF(ISBLANK(DISTINCTCOUNT(Order_table[ORDER_NUMBER])),0,DISTINCTCOUNT(Order_table[ORDER_NUMBER]))
As far as the second problem goes, im not able to find a solution to it and the value for that column for all the rows stands at 0 as I'm writing this answer to 1st problem. Any kind of help or lead will be much appreciated.
Thanks

working with floats mysql

i am customizing a Word Press plugin named Gravity Forms, now the plugin is using a column as datatype float
now i created a totally new interface for displaying the details of an entry that is submitted, i have a set of checkboxes in the form, what Gravity Forms is doing it is adding the field_number as a floats and then the value against it
now for one set of checboxes on my form it is using the field_number as 2 now the 2 remains constants no matter how many checkboxes are selected, and after that comes some points values e.g 2.1 for a specific value and then 2.2 for a specific value and so on upto n times depending on the numbers of checkboxes in the form. please see the below image for more clarification!
Important Note! i cant change the datatype of float as something else e.g vahrchar or decimal it totally messes up the plugin
now i did struggled with getting the float values, because float are not that reliable and easy to use i have seen other blogs where people prefer double or decimal over it
my main problem was this query,
SELECT value FROM wp_rg_lead_detail WHERE lead_id=".absint( $lead['id'] )." and field_number=2.4
now running this query i did not get any result, so what i did is modified my query and passed the value as decimal!
SELECT value FROM wp_rg_lead_detail WHERE lead_id=".absint( $lead['id'] )." and CAST(field_number AS DECIMAL) = CAST(2 AS DECIMAL)
now this query worked just fine and returned the number of rows, but the problem is it is missing some data and not returning all data. like if i have 5 rows as you can see the in the image above its returns only three rows and skips the two rows! any help?
If you want compare with 2 could be you need a truncate instead of a cast eg:
SELECT value
FROM wp_rg_lead_detail
WHERE lead_id=".absint( $lead['id'] )."
and truncate(field_number,0) = 2

Results of calculating with Sum (expression) give a wrong number in SSRS

I have a column which should calculate some numbers and sometimes it gives me the correct sum and sometimes it doesn't. I don't know why! Can someone please point me in the right direction?
I used this expression:
=Sum(Fields!TotalEmployees.Value)
When I don't choose something from filters on the top , it will give me the correct sum:
And when I choose something from the filters on the top, for example between 2 dates, it will give me wrong the sum:
Parameters & Body of report :
#EndDateFrom
#EndDateTo
Yeah, you need to be wary of your grouping. I'm willing to bet you're stuck inside of a group which is filtering your results.
If you are using Report Builder 2016, you can right click your last row and select "Add Total". This will generally automatically generate a row that gets the sum of all fields in your group.
i solved this issue with changing my query ,where all calculating (AVG , Sum &.. ) happens in query , instead reporting services do it for me .. after that i got the correct number:
SELECT t1.Departments, count(t1.id), avg(t1.age),sum(t1.TotalEmployees)/count(t1.id)
AS TotalEmpl FROM (<current_query>) AS t1 <br> GROUP BY t1.Departments

MySQL - Multiplying Time Type Values - Some return 00:00:00

I'm trying to multiplay a field of type time. Sometimes it works and sometimes it doesn't. This is in phpmyadmin with MySQL.
Things I have tried already:
I have tried googling 'sql multiplying time type returns 00:00:00'
but have no luck with that or similar searches.
I ran a python script that pulled all these times and multiplied them
by 6 and 11 and all of them worked - there were no 00:00:00.
I have also tried doing it individually on a row, and it didn't work
for the same ones.
Below are pictures before and after I run this query:
UPDATE journeys, travel_type
SET journeys.jo_duration = journeys.jo_duration * travel_type.tt_duration_multiplier
WHERE journeys.jo_type = travel_type.tt_id
I get no errors.
Some probably helpful information:
Type 1 means 11 - so I want the value in jo_duration to be multiplied by 11. Type 3 means 6 (same principle). 2 means 1 (so nothing changes).
There are more rows in this table that have this problem but I didn't want to screenshot the whole table. I thought this should be enough. There are 70 total rows. When I run the above query it says '47 rows affected' (when all rows should technically be affected I think?). I'm not sure if the remaining aren't affected because they're type 2 or if they're the ones being turned to 00:00:00 (or both)?
If you need more information, feel free to ask!
As you can see below, rows with jo_id; 1, 3, 4, 6 are 00:00:00. But others multiply correctly?
Does anyone know why this is? And how I can prevent it?
Sorry for the long post and I hope my problem has made sense!
Thank you!
Before:
After:
You can't directly multiply number to a time datatype.
Use function time_to_sec and sec_to_time:
update journeys, travel_type
set journeys.jo_duration = sec_to_time(
time_to_sec(journeys.jo_duration)
* travel_type.tt_duration_multiplier
mod 86400)
where journeys.jo_type = travel_type.tt_id
mod 86400 is there to remove the day part if the time becomes more than a day

How use parameters in Loop Activity in IBM Datastage?

I'm in this situation: i have a table of certain data with month associate.
I want load another table with the data of current month and the previous 'n'(i want to insert n).
For example: We are in July(7) and insert 3 as 'n' . the job must be load July-June and May.
It's possible set in Loop activity these parameters?
Such as: FROM: , STEP:-1 , TO: - n (but this form doesn't work)
Or there are other solutions?
Thanks
A loop is not necessary at all - from what I understand - you want to dynamically select the time range from one table to write it to anotherone. The probably easiest way is to use a flexible WHERE Conditrion in the SELECT statement. The WHERE condition or parts of it can be a parameter.
An example could be:
SELECT <whatevercolumns>
FROM <sourcetable>
WHERE date > month(current date) - #NumMonths# months
alternatively
SELECT <whatevercolumns>
FROM <sourcetable>
#WHERE#
And you specify the whole WHERE condition in the parameter.