SSRS -How to get month name from integer value when connecting to IBM-DB2(AS400) - db2

I am using SSRS to create a dataset from a query having a column in AS400 with month number which i get based on a condition .i am able to get the month number . But when i try to get month name SSRS does not accept the query .However if i run the same query on AS400 the query successfully runs
To test my query i ran it in AS400 using MONTHNAME(MONTH) it runs successfully however SSRS does not accept the same query as correct.Below is my query.
SELECT DISTINCT SLMONTH, MONTHNAME(SLMONTH) AS Expr1
FROM VEHICLE.VHTSALSUM
WHERE (SLMGCD = ?) AND (SLMODLCD = ?) AND (SLMODLYR = ?) AND (SLYEAR = ?)

Instead of doing this in on the server, you could just return the month number to SSRS and use an expression to convert it to the month name there.
The expression would simply be
=MonthName(Fields!SLMONTH.Value)
This assumes AS/400 returns month numbers 1 - 12
Personally I think this is a better approach anyway as it means you have the month number to sort by. It is usually better to do your presentation in the report itself.
Edit based on feedback:
To do this for use in a parameter..
Create a dataset that returns just your month numbers.
Right-Click the dataset name and go to properties
On the Fields Tab, add a new field called MonthName for example
Click the function button for the field source type the expression =MONTHNAME(Fields!MonthID.Value)
The month name will then be available directly in your dataset for use in your parameter

Related

Crystal reports formula Syntax

Need help to create a formula in crystal syntax(Crystal reports) to calculate number of days between two dates from WO_DATE.WO_DATE (WO = work order) where WO_DATE_TYPE.WO_DATE_TYPE_DESC = "START" and WO_DATE_TYPE.WO_DATE_TYPE_DESC = "Due".
Below is my DB Schema
In Crystal's database expert, add the WO_Date table twice. The 2nd instance would require an Alias (a different name).
Join to require the Work_Order_ID be the same across the two instances.
In the record selection formula, force the first instance to be the START type.
Similarly, force the second instance to be the END type.
Now, simply subtract the date in the first table instance from the date in the second table instance.

Power BI convert eight digit yyyymmdd to date using DAX

I'm trying to convert eight digit yyyymmdd to date format with DAX function.
column = DATE(LEFT(TABLE[COLUMN],4),MID(TABLE[COLUMN],5,2),RIGHT(TABLE[COLUMN],2))
However, I've got an error because of the original column has some records with "00000000", so how can I make a default value with IF statement or are there any better solution?
Best regards
What I typically do is just make 2 distinct Power Query steps and this is handled automatically.
just make the yyyymmdd column a text column
make the text column from step 1 a date column (when prompted, be sure to select 'Add New Step')
replace errors with null
That's it. You can even Ctrl-Click to select multiple columns and combine them into the 1,2, and 3 steps with multiple columns.
Please check out "ferror" function IFERROR(value, value_if_error) for more information please visit Microsoft MSDN with link below
https://msdn.microsoft.com/en-us/library/ee634765.aspx
column = IFERROR( DATE(LEFT(TABLE[COLUMN],4),MID(TABLE[COLUMN],5,2),RIGHT(TABLE[COLUMN],2)), DATE(yyyy,mm,dd))

Dynamic Computation in Tableau based on User Input

I have a requirement to dynamically perform computations in Tableau based on User Input.
For this purpose my basic query looks something like this:
Select some_dimension,sum(some_measure)/count(some_measure) as
some_measure_average
from table
where date = User_Input
group by some_dimension
The User_Input value should be passed based on what the user has selected and the corresponding computation should be performed based on the above query logic.Here , the Custom SQL should hit the connected Database that contains the data and display the computed data on Tableau.
Here the average is calculated based on the division of sum and count and should only be computed for the date value that has been selected.
The Custom SQL Query option in Tableau is not able to fulfill this requirement.
Not sure if we are doing it correctly.
You can create a date parameter in Tableau and pass that as your User_Input. Type your query and click "Insert Parameter". Set the parameter Data type to Date and provide a current value. Insert it where needed in your query.

Create a chart using the records of certain type grouped by month, with a moving balance

I am trying to create a chart (bar or line) in crystal from one table in my database (Sage CRM).
The records are as follows
CustomerId Date Invoice Amount
1234 3/4/2013 Cust Invoice 3322.00
1234 3/4/2013 Payment 2445.00
1234 4/5/2013 A/c transaction 322.00
1234 5/6/2013 interest 32.00
1234 6/6/2013 payment 643.00
So I would like to have a report that meets the following criteria
Only records for the last 12 months grouped in month
Only invoice types of payment, invoice and interest
A moving balance that calculates all the invoice amounts ie
(when displaying the information for July 2012, the moving balance will be the total of all invoices prior to this date.
Without this field I can create the chart no problem using select expert but I am not sure now what to do)
Should I use a cross tab? if so how will I do the selection to only show the invoices I want and the the date range I want?
After spending almost a week on this problem, with a lot of help from an expert I have finally got a solution.
In order to create a amount that is the sum of all records for a company, month and invoice type since the beginning of time, while only displaying records for the last year, I have created a SQL command
Select
//All of the fields for the report,
movingBalance.Amount
from myInvoiceTable as mit
<join to any other tables for the report>
left join (
select customerID, sum(amount) as Amount
from myInvoiceTable
where Record_Type in ('Payment', 'Invoice','Interest')
and Date < {?Report Start Date}
group by customerID) movingBalance
on mit.customerID = movingBalance.customerID
where mit.RecordType in ('Payment', 'Invoice','Interest')
and mit.Date >= {?Report Start Date}
and mit.Date <= {?Report End Date}
There are a couple of tricks to using commands:
For performance reasons you generally want to include ALL of the data for the report in a single command. Avoid joining multiple commands or joining one or more tables to a command.
Filter the data in the command, NOT in the Select Expert in the report.
Create any parameters in the Command Editor, not in the main report. Parameters created in the report won't work in the Command Editor.
This has done the trick.
Create Date Parameters in the report to filter out the records at the time of fetching now when you run the report you have left with the data you need.
Now you can manuplate the data inside report using formula fields.
Accoding to me writing stored procedures is a bit hectic task as you can manuplate the data inside the report. I don't have any intentions to disrespect anyone opinions but frankly its my opinion.
In that case Rachsherry I would recommend the following.
For criteria parts 1 & 2 I think instead of using stored procs, it may be easier for you to use a formula.
For invoices right click the invoice field, then "Format Field" in the common tab next to the Suppress option there is a formula button, enter the following...
IF {YourInvoiceField} IN ["Payment", "Invoice", "Interest] THEN FALSE ELSE TRUE
For your date requirement you need to use a selection formula... The code for that should look something like this
{YourDateHere} > DateAdd ("yyyy", -1, CurrentDate) AND {YourDateHere} < CurrentDate
The above code basically looks at dates between the day the report is run, and exactly a year before.
For your moving balance, you should be able to achive that with the guide here
Edit - An alternative to this is to use parameter fields (Which I don't personally like) it just means having to input the parameters every time the report is refreshed, they are self explanatory but you can find a guide here

SSRS 2008 - Multiple Groupings For Date Range

A record in a table contains a range of valid dates, say:
*tbl1.start_date* and *tbl1.end_date*. So to ensure I get all records that are valid for a specific date range, the selection logic is: <...> WHERE end_date >= #dtFrom AND start_date < #dtTo (the #dtTo parameter used in the SQL statement is actually the calculated next day of the *#prmDt_To* parameter used in the report).
Now in a report I need to count the number of records for each day within the specified data range and include the days, if any, for which there were no valid records. Thus a retrieved record may be counted in several different days. I can do it relatively easily with a recursive CTE within the data set, but my rule of thumb is to avoid the unnecessary load on the SQL database and instead return just the necessary raw data and let the Report engine handle groupings. So is there a means to do this within SSRS?
Thank you,
Sergey
You might be able to do something in SSRS with custom code, but I recommend against it. The place to do this is in the dataset. SSRS is not designed to fill in groups that don't exist in the dataset. That sounds like what you are trying to do: SSRS would need to create the groups for each date whether or not that date is in the dataset.
If you don't have a number or date table in your database, I would just create a recursive CTE with a record for every date in the range that you are interested as you mention. Then outer join this to your table and use COUNT(tbl1.start_date) to find the appropriate days. This shouldn't be too painful a query for SQL server.
If you really need to avoid the CTE, then I would create a date or number table to use to generate the dates in your range.