Parameterize MDX in SSRS - sql-server

Relatively new to MDX but familiar with SSRS and I have a query that works just as I want it to in the query designer in SSMS however I'm not quite sure how to parameterize this in SSRS.
Query returns department and shift as dimensions and Hours and Period as Measures with the query being filtered by a fiscal year and the Period measure as a specific period for that year.
Query works as expected but do not know how to convert to SSRS by implementing parameters for Fiscal Period and Fiscal Year.
Query:
WITH MEMBER [measures].[Period] AS
SUM([Date].[Fiscal Period].[P9],[Measures].[Hours])
SELECT NON EMPTY [Department].[Department].[Department] * [Associate].[Current Shift].[Current Shift] on Rows,
{[Measures].[Hours], [Measures].[Period]} ON Columns
FROM Personnel
WHERE [Date].[Fiscal Year].[FY2015]

Create two parameters for Fiscal year and Fiscal Period. Then use the below query:
SELECT NON EMPTY [Department].[Department].[Department] * [Associate].[Current Shift].[Current Shift] on Rows,
[Measures].[Hours] ON Columns
FROM Personnel
WHERE
(
StrToMember(#FiscalYear, CONSTRAINED),
StrToMember(#FiscalPeriod, CONSTRAINED)
)

Related

Creating Attendance Report with SSRS

I am trying to create a Attendance result set in SQL Server for using it in a SSRS report. The Employee Attendance table is as below:
EmpId
ADate
In
Out
1
2023-01-01
8:00
15:00
I need to calculate the Total working days for all months in a year and display the number of working days per employee. Report format should be as follows:
Saturday and Sunday being weekend, I can able to get the no of working days monthly.
Another table tbl_Holiday has entries for holidays Fromdate and ToDate. I need to consider that also when calculating working days. Several number of results i got from the internet for calculating this. But when creating a view using this data , it has to calculate workdays for each employee row
SELECT
EmpName, EmpId,
(SELECT COUNT(*) FROM tbl_EmpAttendance
WHERE EmpRecId = A.RecId
GROUP BY MONTH(Adate), YEAR(Adate)) AS WorkedDays,
dbo.fn_GetWorkDays(DATEFROMPARTS(YEAR(ADate), MONTH(ADate), 1), EOMONTH(ADate)) AS workingDays
FROM
tbl_Employee A
LEFT JOIN
tbl_EmpAttendance B ON A.RecId = B.EmpRecId
fn_GetWorkDays - calculates the working days for month.
I need to get number of holidays from tbl_holiday too, I understand that this query is becoming more complex than I thought. There must be simpler way to achieve this, can anyone please help?
I tried to get the result in one single view, for using that as SSRS report dataset

How do I create a pivot/crosstab query in SQL Server when I don't know the column names in advance?

I am querying some sales figures in SQL Server to determine sales by customer by year. This is easy in Access:
TRANSFORM Sum(dbo_HISTORY.NET_SALES) AS SumOfNET_SALES
SELECT dbo_HISTORY.CUSTOMER_NAME
FROM dbo_HISTORY
GROUP BY dbo_HISTORY.CUSTOMER_NAME
PIVOT dbo_HISTORY.YEAR;
In SQL Server, I can add things easily enough:
SELECT [SPEC_MIS].DBO.HISTORY.CUSTOMER_NAME,[SPEC_MIS].DBO.HISTORY.YEAR,sum([SPEC_MIS].DBO.HISTORY.NET_SALES) AS SALES
FROM [SPEC_MIS].DBO.HISTORY
GROUP BY CUSTOMER_NAME,YEAR
ORDER BY CUSTOMER_NAME,YEAR
But I can't work out how to get the pivot to work. Note that I need this query to work on any arrangement of years, I don't want to have to rewrite this query every year.

Report is Slow in SSMS and timing out in SSRS

I have table that stores about 250K rows of data. the select * query takes about 15 seconds to run in SSMS. Rendering the report in SSRS is not working. It just keep loading for about 5 minutes and sometimes works and other times out. Here's my two questions:
Is there a way to speed up the select query in SSMS?
Is there fix to the issue I'm having in SSRS?
I have tried converting the query into a stored procedure. Still the same problem in SSRS.
I have tried adding a new column to the table which assigns the same id for group of rows based on the date column. i.e. if the year of the date column is 2017 then all rows with this year will have id column = 1 and if it's 2018 then the id column = 2
I have tried limiting the number of rows in each page in SSRS but, still no luck.

Group date by month in Pivot table using data from MS SQL Server

This is my pivot table and I have sales amount from 6 months. I want to group these dates by month but the group button is disabled/not allowing me to do so.

Display a yearly summary by month in SQL

I have a table that has a date/time field and am trying to figure out how to run a report so that I can view the sum of the amount between each month separately in the 2012 year.
The table has 2 fields, Amount and TimeStamp, and I'm trying to return a report like this:
January, 2012: $221.20
February, 2012: $150.20
etc etc.
Anyone have any ideas how to accomplish this easily in SQL Server? I want to avoid writing a seperate query for each individual month.
This can be solved by using the MONTH and YEAR Functions on SQL.
SELECT
SUM(Amount) as [Amount]
,MONTH(TimeStamp) as [Month]
,YEAR(TimeStamp) as [Year]
FROM
[MyTable]
GROUP BY
MONTH(TimeStamp)
,YEAR(TimeStamp)

Resources