MTD, QTD, YTD Aggregation - reportingservices-2005

I'm trying to build a report aggregation that contains Client Name, Row Date, Offered, Handled, and other metrics. I'm not able to figure out how to aggregate the metrics for MTD, QTD, YTD for Offered, Handle and other metrics. In tableau, i was able to apply this method using this code SUM(IF [Row date] <= [SelectedDate] AND MONTH([Row date]) = MONTH([SelectedDate]) AND YEAR([Row date]) = YEAR([SelectedDate]) THEN [Handled] END ), but i'm not able to apply it in SSRS. Please advise . thanks.

Related

Subtotal plus limiting data set

I'm brand-spakin' new to SQL and was asked to help write a query for a report. I need to limit the data to the last 10 services done by a clinician, and then subtotal the difference between the two times (time in and out) for each clinician.
I'm guessing I need to do a "LIMIT" clause to limit the data, but I'm not sure how or where to put that information. I am also thinking I need to use "GROUP BY", but not positive on that either. Any help would be appreciated.
I tried simplifying the existing query that my boss started but I'm getting error messages about the GROUP BY clause because I don't have an aggregate.
Select CV.emp_name,
CV.Visittype,
CVt.clientvisit_id,
CV.client_id,
CV.rev_timein,
CV.rev_timeout,
Convert(varchar(25),Cast(CV.rev_timein As Time),8) As Start_Time,
CV.program_id,
CV.cptcode
From ClientVisit CV
Where CV.visittype = 'Mobile Therapy' And CV.program_id = 31
And CV.cptcode <> 'NB' And CV.rev_timein <=
Convert(datetime,IsNull(#param2, GetDate())) And CV.rev_timein >=
Convert(datetime,IsNull(#param1, GetDate())) And
Cast(CV.rev_timein As time) > '15:59'
Group By CV.emp_name,
CV.rev_timein

Show only last occurence of the field

I have an issue with a report I am trying to make in SAP. The problem is that I want to only show each SR NUM only once. But there are many appearances in my report. I saw that each number has multiple activities and comments and that is why there are appearing more than once. The thing is that I only need the last appearance based on date for each SR Num and there is no filter that can help me with this. I also tried Ranking but I do not have a metric and created a new variable finding max date for each sr num. That also did not work as there are multi values.
Please help!
For example i have 3 columns sr num, date and comments. The first has 3 different nums but multiple times and the dates are all different as the comments.I need to only keep each sr num once with the most recent date and comment
I created some sample data in a free-hand SQL query which yields this...
You will need to find the maximum date for each SR Num and then only show that row for each SR Num. I used two variables to achieve this.
Var Max Activity Date...
=Max([Activity Date]) In ([SR Num])
Var Is Max Activity Date...
=If([Activity Date] = [Var Max Activity Date]; 1; 0)
Finally add a table filter to only show the rows where the Activity Date is the Max Activity Date for each SR Num.
You do not need the variables in your table in the end. I just put them there in order to visualize what is going on. That's it.
Noel

HOW TO REFERENCE A MEASURE IN A FILTER (DAX)

I have created a measure
Report_Day = MAX(DATE_LT[Date])-2
I want to create measures where they reference this measure so i can just change -2 to -1 and the rest of measures work depending on the reporting date.
when i use this measure:
Day_outlet_Txns = CALCULATE(
[outlet_Dep_Txns],
FILTER(ALL(DATE_LT),[Report_Day])
)
i get a value equal to tatal transactions in a table yet i want for transactions of that report day.
When i try something else
Day_outlet_Txns = CALCULATE(
[Issuer_Dep_Txns],
FILTER(ALL(DATE_LT), DATE_LT=[Report_Day])
)
i get an error: The expression refers to multiple columns. Multiple columns cannot be converted to a scalar value.
enter image description here

Reuse calculated table variable within DAX formula

I have the following DAX formula for a measure, and it works fine.
Gross Area =
var as_on = LASTDATE('Calendar'[Date])
var all_latest_dates =
ADDCOLUMNS(
VALUES('Unit Revision'[Unit Id]),
"Last Event", CALCULATE(
MAX('Unit Revision'[Event Date]),
'Unit Revision'[Event Date] <= as_on
)
)
var unit_latest_dates = TREATAS(all_latest_dates, 'Unit Revision'[Unit Id], 'Unit Revision'[Event Date])
RETURN
CALCULATE( SUM('Unit Revision'[Gross Area]), unit_latest_dates )
I need to calculate more metrics using a similar logic, where the DAX formula is the same until the RETURN statement, and just the column name within the final CALCULATE( SUM() ) differs.
I then need to add all these measures to a Matrix. In such as case, will the variable calculation of theĀ unit_latest_dates table be calculated for every DAX measure, or will it be cached? To ensure it is cached, is it possible to reuse the initial set of DAX code within a calculated table measure or something, just like how we can reuse a scalar measure in another measure?
I can't use this in a Calculated Table, as the calculation changes based on changes in the Calendar Table Date slicer.
Yes, it should be cached as long as DAX Engine can understand that a similar query was executed earlier and it didn't involve a CALLBACKDATAID and was executed only by Storage Engine and not Formula Engine, try to use DAX Studio and see if it is doing that or not.

Combining all dates, and data, within a month!

I am trying to combine all days of each month into a date.
My query as off now:
SELECT
inventory_items.acquired_at AS Date_Acquired,
products.name AS products_name,
SUM(inventory_items.primary_quantity) AS inventory_items_primary_quantity
FROM
inventory_items inventory_items INNER JOIN customers customers ON inventory_items.source_id = customers.id
INNER JOIN products products ON inventory_items.product_id = products.id
GROUP BY
MONTH(Date_Acquired),
products_name
ORDER BY
MONTH(Date_Acquired)
I have a general idea of what to do, but not really sure how to implement it.
As I understand you and your Date_Acquired is an instance of sql Date type
you can gat day of months as pasting below code inside a textfield
(new SimpleDateFormat("d")).format(new java.util.Date())
which suppose to give you numbers like 1,2,3,...18,19...
Extra:
(new SimpleDateFormat("M")).format(new java.util.Date()) for month
(new SimpleDateFormat("yyyy")).format(new java.util.Date()) for year
(new SimpleDateFormat("d")).format(new java.util.Date())+" - "
+(new SimpleDateFormat("M")).format(new java.util.Date()) for getting a value like 28 - 01
What database? A typical SQL database result can only contain one data value per field. So you will not be able to retrieve all the products.name values in one result grouped by the month. If you retrieve all the results under a specified month you can aggregate them later on.

Resources