on 2017 Feb 05 4:20 AM
Dear SCN Members,lars.breddemann,
In finding the “Maximum number of materials used for each Material Type at a given date” (On three Material Types).
Projection 1:
Material Type (Filter = Material Type A)
Material Start Date Time
Flag = 1
Projection 2:
Material Type (Filter = Material Type A)
Material Start Date Time
Flag = -1
Then I have made a union of Projection 1 and Projection 2 as Calculation View 1
Then I have taken a Running Total based on Date Time i.e., Time stamp as follows using windows function as Calculation View 2
var_out =
select "Material Type","ACTIVITY_DATE_TIME",
sum("FLAG") over (order by "ACTIVITY_DATE_TIME" rows unbounded preceding) as "RUNNING_TOTAL"
from "Calculation View 1";
Apologies: I will use TF in place of Calculation Scripted Views.
Then I have taken a Max of Running total based on a given date, by extracting a date from the above Calculation View 2 and it is called as Calculation View 3
Semantics of Calculation View 3 are as follows
Material Type Activity Date Time Hidden Running Total Max Activity Date
Additional Requirement: To have an entry for 1 week additional to Activity Date, with Null as Running Total, performed the following as Calculation View 4:
DECLARE var_1 DATE;
DECLARE var_2 DATE;
SELECT ADD_DAYS (TO_DATE(MAX("ACTIVITY_DATE"), 'YYYY-MM-DD'),1) INTO var_1
FROM Calculation View 3;
SELECT ADD_DAYS (TO_DATE(MAX("ACTIVITY_DATE"), 'YYYY-MM-DD'),8) INTO var_2
FROM Calculation View 3;
temp_1 = SELECT "GENERATED_PERIOD_START",
"GENERATED_PERIOD_END",
"ELEMENT_NUMBER"
FROM SERIES_GENERATE_DATE(
'INTERVAL 1 DAY', :var_1, :var_2);
var_out= SELECT "Material Type","RUNNING_TOTAL","ACTIVITY_DATE" "GENERATED_PERIOD_START",'' "GENERATED_PERIOD_END"
FROM Calculation View 3
UNION ALL
SELECT
'Material Type A',null"RUNNING_TOTAL","GENERATED_PERIOD_START","GENERATED_PERIOD_END"
FROM :temp_1;
Similar approach I have taken for Material Type B and Material Type C, hence there are 12 views in total which is made union at the end.
Here, I am in a dilemma, even though the requirement is achieved from the above process but it increased the calculation for each material type i.e., for three material types I needed (3*4)+1 = 13 views which is not a good design since Material Type is dynamic and will be added very frequently which needs changes regularly by adding additional 4 views.
Please suggest if I have missed anything in the above design and it can be improvised in a better fashion since there is no input parameter for this requirement as the consumer of the final view is Business Objects Data Services.
Thanks in advance!
Best Regards,
Nachappa S
Ok, I've been rather busy lately and you didn't bother putting in actual SQL *code* so that your example is not easy to reproduce.
If you want a quick answer, heck, if you want an answer at all, never ever make people type in your example data!
I had a quick go at it and I would do it in SQL like this:
select "ACTIVITY_DATE_TIME", "MATERIAL_TYPE", max("USAGE_COUNTER") as max_usage
from (
select "ACTIVITY_DATE_TIME", "MATERIAL_TYPE",
sum("FLAG") over
(partition by "MATERIAL_TYPE"
order by "ACTIVITY_DATE_TIME" asc
rows unbounded preceding) as "USAGE_COUNTER"
from (
/* checkout material */
select material_type, to_date(start_datetime) as activity_date_time, 1 as flag
from mat_prod
union all
/* checkin material */
select material_type, to_date(end_datetime) as activity_date_time, -1 as flag
from mat_prod
union all
/* neutral material entry for each day */
select mats.material_type, t.date_sql as activity_date_time, 0 flag
from
"_SYS_BI"."M_TIME_DIMENSION" t
cross join
(select distinct material_type from mat_prod) mats
where date_sql between '2016-01-01' and '2016-02-01'
)
)
group by activity_date_time , material_type
order by activity_date_time asc, material_type asc ;
Using the time series generator is not bad or anything, but the M_TIME_DIMENSION table is doing pretty much the same thing here.
Currently, the cross join to produce the neutral entries for each material for each day only considered what is already in the table (e.g. only the materials that have been used at least once. If you want to make it work for all materials you need to look at the master data table here.
Other than that, this solution is independent of how many materials there are.
I didn't look into the new requirement you mentioned, but that looks straight forward to add.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
66 | |
10 | |
10 | |
10 | |
10 | |
8 | |
6 | |
5 | |
4 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.