I have to fetch data from table MonthWise. I have created a PARAMETER - #SELECTMONTH and kept this parameter as static. I had put specific value in available values i.e.
for eg. Label - Jan Value - Jan
Label - Feb Value - Feb and so on
I have used this parameter in query. i.e.
Select Month FROM Table WHERE Month in (#SelectMonth)
Union all
Select 'Jan-Feb' as Month FROM Table Where Month in ('Jan-19','Feb-19')
Union all
Select 'Jan-Feb-Mar' as Month FROM Table Where Month in ('Jan-19','Feb-19','Mar-19')
Under DataSet Properties > Parameters > Add > Parameter Name - #SelectMonth and Parameter Value - [#SelectMonth] - under this expression is =Parameters!SelectMonth.Value
All this are the factors in report. and when report runs I am able to see SelectMonth Parameter and able to select multiple months and data is been displayed accordingly I select the months.
But this is 50 % of requirement only done. Another requirement is I have to display months at the end of the report, which is written in UNION ALL query. I am able to display it by use of UNION ALL query. But the requirement is to display as per the month selected in parameter checkbox.
For eg. If I select Jan-Feb-Mar, than it should display as
Jan
Feb
Mar
Jan-Feb
Jan-Feb-Mar
But if I deselect for eg. Mar, than it should remove Mar from the Month which is at the end of report. Here I am able to remove from single month, as required month Mar is not showing/data is not been fetched in single month field but it is till fetching month Mar in end where it is joining months Jan-Feb-Mar. I do not even want that month Mar to be joined at end either. it should be removed totally from everywhere. it is should look like as below: but I am not able to do it.
Jan
Feb
Jan-Feb
If anyone can help that how should I put it ? I was wondering to use IF condition, that IF #SelectMonth = 'Jan' then only that much data should be displayed in single month column and even to the join month column.
But i am not able to figure out exactly. so please if anyone can help that will be great.
Thank you so much everyone in advance.
Related
I have an SSRS report that has all 12 months as columns and one more column called "Year". I already have a condition set that takes the current month of the report run date and displays only the months that have passed. For example, the expression looks like this for March =IIF(Month(today()) < 3, True, False).
Now I have to tie this to the Year column as well. The condition is- if the Year column has years prior to the current year, the condition above should not apply. So, if I am running 2020 data today, all 12 month columns should appear. If I am running 2021 data, I should only see the January column. Can some one please help me with this? And yes, there will only be one year in the "Year" column. The data will never have more than one year.
Thank you.
Edit 1:
If the report is run for 2020, the data should look like this on the report.
If it is run for 2021, only the YEAR and JANUARY columns should appear. Starting February of this year, YEAR, JANUARY, AND FEBRUARY should appear.
As your dataset is not normalised, you will have to set the column visibility on each column as you are doing already.
Try using the following expression. (using March as an exmaple)
=(Month(today()) < 3 AND MAX(Fields!Year.Value, "DataSet1") = YEAR(Today())
Note: The "DataSet1" reference is the name of your dataset. It is case sensitive and must be enclosed in quotes as shown above.
There is no need for the IIF() expression as the above will return true if either condition is met.
Alternative
If your data was normalised (you may be able to edit your dataset query) and looked something like this...
Year Month Amount
2021 1 10
2021 2 15
Then you could simply use a matrix instead of a table, and have a column group by month. There would be no need to set visibility on anything as the data simply is not there so no column would be rendered for the months with no data.
Populate a cell in SSRS report by testing value conditions from other column values
I have 3 columns (category, Month, Amount) in my dataset, with values similar to these below:
Category Month Amount
A Jan 20
A Feb 25
A Mar 10
R Jan 15
R Feb 50
R Mar 55
On the report I need:
Jan Feb Mar
A 20 25 10
R 15 50 55
I have tried placing this expression in each group row column, for example, in the "Feb" column it would be:
=IIF(Fields!Category.Value = "A" and Fields!Month.Value = "Feb", Fields!Amount.Value, 13)
Using IIF, which does not short-circuit, is not evaluating the conditions properly. The "Month" value being a string, it displays always the first row found for the conditions, in this case it would display value 20, instead of 25. If I change the "Month" value to int, it displays the false(13);
How can I populate my cell correctly, using IIF or something other way?
Any help on this is deeply appreciated.
You don't need to do anything like that.
Just use a matrix instead of a table.
Add the matrix to the report, you'll see three placeholder names, (from memory) something like Rows, Column and Data. Drag your Category field to the rows cell, your month field to the columns cell and your Amount field to the data cell. That's it....
The only problem you will have is the columns would be ordered alphabetically by default. It would be better to have the Month number in your dataset too so you can order by that. You set the column order by right-clicking the column group name in the row/column group panel which is under your main report design area.
I am trying to find out how can I write the below logic in SSRS:
The structure of my report is:
All the rows and columns are grouped together.
The New Week Status has 2 fields: Current Week and Previous Week.
Current Week ranges from 30th Jan - 5th Feb
Previous Week ranges from 23th Jan - 29th Feb
The Gross Sales is in %.
I need to display only those restaurants where at least 5 days in Current Week and Previous Week is above 2% Gross.
Example:
In the above example, R1 has more than 5 days > 2%, so it will be displayed
R2 has less than 5 days > 2%, so it won't be displayed
How can the logic be implemented for this?
If you are not calculating the Gross Sales in the report this could work for you.
Select the whole Restaurant row and right click it, select Row Visibility... option:
Select Show or hide based on an expression: and use this expression:
=IIF(SUM(IIF(Fields!Gross_Sales.Value> 0.02,1,0))>=5,False,True)
Now only rows with at least 5 dates that have more than 0.02 (2%) Gross Sales are visible.
UPDATE: Adding examples.
I've recreated your dataset and the matrix, so having this structure:
Using the expression I posted above it hides the R2 row as expected.
UPDATE:
=IIF(
SUM(IIF(Fields!Total_Cost.Value/Fields!Sales_Gross.Value>0.02,1,0))>=5
or
SUM(IIF(Fields!New_Week_Status.Value = "Current Week" and Fields!Total_Cost.Value/Fields!Sales_Gross.Value>0.02,1,0))>=3
,False,True)
I have some records in a query with a column of dates. I want it to only show the records that occur in March. This link
https://support.office.com/en-US/Article/Examples-of-query-criteria-3197228c-8684-4552-ac03-aba746fb29d8#bm1 shows the different types of criterion.
The one below in the table describes how to show only what occurs in a particular month:
"Contain a date that falls in a specific month (irrespective of year), such as December
DatePart("m", [SalesDate]) = 12
Returns records where the transactions took place in December of any year."
I don't know what the SalesDate means in the criteria function, and there isn't any explanation on the page.
[SalesDate] implied a Date/Time field named SalesDate. If your Date/Time field is named something else, such as invoice_date, substitute that name in the DatePart expression:
DatePart("m", [invoice_date]) = 12
For March instead of December invoices, use this:
DatePart("m", [invoice_date]) = 3
You could also use Month() instead of DatePart to get the same result:
Month([invoice_date]) = 3
Using MySQL and PHP I am building a JSON array to populate a data table.
For the purposed of my question suppose the data table has the following columns:
Year: 2010,2011,2012,2013...<br/>
Month: 1,2,3,4,5...<br/>
Value: 100, 150, 200 etc...<br/>
The table structure cannot be altered and my solution needs come into the MySQL query
The data can be viewed either monthly, quarterly or yearly. Monthly and yearly is achieved easily through grouping by year and month.
Quarterly data can be grouped by calendar quarter (Jan-Mar, Apr-Jun, Jul-Sep, Oct-Dec) by this group statement:
GROUP BY year, round((month/3)+0.3,0)
So where Jan, Feb and March might all have 100 for their value the summed result is 300, same for other months.
Now my problem comes when I want to group values by a financial quarter, for example a quarter that starts in Feb, or any other quarters.
I have a statement that works for the quarter grouping using two variables that can be accessed via the SQL query, start_year (i.e. 2014) and start_month (i.e. 2)
GROUP BY year, (((round(((((month-(start_month-1))+((year-start_year)*12))-((year-start_year)*12))/3)+0.33,0)/4)+4)-floor(((round(((((month-(start_month, '%m')-1))+((year-start_year)*12))-((year-start_year*12))/3)+0.33,0)/4)+4)))*12
which basically will assign a 0,3,6,9 value to each calendar month for the purposes of grouping.
In the financial year starting February this works fine for quarters 1-3, however breaks for the final quarter as it includes Nov and Dec 2014 data and Jan from 2015.
As a result I get 5 rows of data instead of 4.
This is because of the preceding GROUP by year clause, an important addition as we might want to generate a table that views sequential quarters for multiple years.
So what I am looking for is a way of grouping the years together by offsetting the start month.
So when the year starts in Jan it will group Jan-Dec but if we change that to starting Feb it will group Feb-Jan.
Any ideas, suggestions most welcome!
Regards,
Carl
I solved a similar problem just now (a Moodle report aggregating assignment scores by year and quarter) with something like this:
select year(from_unixtime(s.timemarked)) as year, quarter(from_unixtime(s.timemarked)) % 4 + 1 as quarter, count(distinct data1) as "tickets graded" from mdlassignment_submissions s where grade >= 0 group by year, quarter order by year, quarter;
The relevant part for what you're doing is quarter(from_unixtime(s.timemarked)) % 4 + 1 as quarter
As another commenter pointed out, MySQL has a quarter() function, but it doesn't do financial quarters. However, since (as I understand it, at least, based on consulting the relevant wikipedia page) financial quarters are just offset by 1, the % 4 + 1 at the end should convert it.