PowerBI Report Builder Nested Previous - aggregate-functions

I have a report like this:
OPERATOR|WEEK_ENDING_Date|OpeningStock|TOTAL_RECEIVED_QTY|TOTAL_RETURNED_QTY|WeekEndingClosing
Supposed
OpeningStock = Last Week of WeekEndingClosing
WeekEndingCLosing = OpeningStock + TOTAL_RECEIVED_QTY - TOTAL_RETURNED_QTY
The calculation is grouped by Operator.
I used tried following expression to compute the OpeningStock but hitting error.
Expression:
=Previous(SUM(Fields!TOTAL_RECEIVED_QTY.Value- Fields!TOTAL_RETURNED_QTY.Value) + IiF(Previous(First(Fields!OPERATOR.Value), "WEEK_ENDING_Date")=Fields!OPERATOR.Value,
Previous(SUM(Fields!TOTAL_RECEIVED_QTY.Value-Fields!TOTAL_RETURNED_QTY.Value), "WEEK_ENDING_Date"),
Nothing)))
Error:
The Value expression for the textrun 'Textbox306.Paragraphs[0].TextRuns[0]' uses a Previous function in an outer aggregate. Previous functions cannot be specified as nested aggregates.
Appreciate for your input how can I put the expression in correct way so that the WeekEndingClosing can be brought over to Next week as OpeningStock since nested Previous is not allowed.

Related

How can I format a time variable to include colons? (JDE Event Rules)

I'm trying to create an ER that adds colons to my time variable in JDE (OMW). I've tried using the substring function to make 3 substrings and then add a colon inbetween each substring, but that doesn't seem to be working for some reason.
Here is what I tried to do as a test to see if the substring would work.
substr([PC Time - Last Updated (F0911) (UPMT)],0,2 )
This should cut my time from an 8 digit number to a 2 digit number, but it doesn't seem to be doing anything. Any ideas? Currently this line of code is in the DO section of my event rules.
You can achieve what you want using the substr function. But you will have to give the function your time. From your code, i can see you used a "PC" variable.
substr([PC Time - Last Updated (F0911) (UPMT)],0,2 )
Which relate to the previous value inside the business view. Maybe you wanted to use a "BC" one? Because the first record will always be null for a "PC" variable Inside a DO SECTION event rule. Just make sure you are sending a value to the substr function.

Xquery Where clause not working when using nested query

Good Day,
I'm new to xquery.
I'm trying to execute xquery with a where clause that returns the values greater than a value returned from a nested query as show below. It runs but returns values that are not greater than the returned value
If I use the where clause directly with the value it works fine. I'm using BaseX to execute my query. Appreciate any feedback, I believe the parser may be reading my subquery wrong.
for $y in doc("url.xml")/taxi_stations/stand
where $y/taxis>=
(
for $x in doc("url.xml")/taxi_stations/stand
where $x/name="Jacksonville"
return data($x/taxis)
)
return ($y/taxis,$y/name)
What is the value of $taxis? It's possible your comparisons are happening on strings, not numbers.
In your nested return, you call data() on $x/taxis - assuming that correctly returns a number value, then $y/taxis in your outer where clause should probably also be wrapped in data().
However, if there is no schema on your document, then data() will simply return a string. In that case you should convert your taxis element to a number using fn:number() or directly casting it like $y/taxis/xs:integer(.).

PL/R - Pass entire column as an argument

I am trying to write a simple PL/R function that finds the mean of a column (Greenplum 4.3.4 DB)
CREATE OR REPLACE FUNCTION mean_plr(val numeric[]) RETURNS numeric AS
$$
x <- val
avg = mean(x)
return(avg)
$$
LANGUAGE 'plr';
SELECT mean_plr(sensor1) FROM public.tempSensors;
This, however, gives me the error:
ERROR: function mean_plr(numeric) does not exist
LINE 1: SELECT mean_plr(sensor1) FROM public.tempSensors;
^
HINT: No function matches the given name and argument types. You may need to add explicit type casts.
Figured out what I was doing wrong. mean_plr(sensor1) sends 1 value at a time. To send entire column, we need to use array_agg() function.
SELECT mean_plr(array_agg(sensor1::numeric)) FROM public.tempSensors;

How to get the expression used in an Assign activity

In the line below, "ThenActivity" is an Assign activity nested inside the Then part of an If activity. Im trying to get at the expression, but this snippet isnt working.
((Assign)ThenActivity).To.Expression.ToString();
This returns "1.13: CSharpReference"
When it should read R = 44.5M, which is the expression text, how do I get at it?
The statement should read something like this
((CSharpValue)(((Assign)ThenActivity).Value.Expression)).ExpressionText
Note: You need to get the assignment, then its expression, cast that as a CSharpValue, then finally you can get the ExpressionText.

SSIS: Comparing datetime with a variable

So, I have created a variable "batch" with datatype datetime. Now my OLEBD source has a column "addDate" eg 2012-05-18 11:11:17.470 so does empty destination which is to be populated.
now this column addDate has many dates and I want to copy all dates which are "2012-05-18 11:11:17.470"
When I put value of the variable as this date, it automatically changes to mm/dd/yyyy hh;mm AM format and hence in my conditional split transformation, it couldn't match the date with the variable and hence no records are getting copied to the destination !!
Where exactly is the problem?
Thanks!
I had this issue and the best solution I found is not “pretty”.
Basically you need to change the “expression” of the variable and the “evaluate as expression” to true (otherwise it will ignore the value on expression).
The secret is (and kind of the reason I said it is not a pretty solution) to create a second variable to evaluate the expression of the first variable because you can’t change the value of a variable based on a expression.
So let’s say your variable is called “DateVariable” and you have 23/05/2012, create a variable called “DateVar2” for example and set its expression to
(DT_WSTR,4)YEAR(#[User::DateVariable]) + "/"+RIGHT("0" +
(DT_WSTR,2)MONTH(#[User::DateVariable]),2) + "/" + RIGHT("0" +
(DT_WSTR,2)DAY(#[User::DateVariable]),2)
That will give you 2012/05/23
Just keep going to get the date on the format you want
I found the easier solution. Select datatype as string. put any desired value.
Before conditional split, you need data conversion transformation.
convert it into DT_DBTIMESTAMP then run the package.
It works!

Resources