I am trying to create a "Received" bool field on both the Purchase Lines and the Sales Lines, so that when an item is marked as True on the Purchase Line, the linked Sales Line is also marked as True. So far I have managed to create a field on the Purchase Line to store the id of the associated Sales Line, but I am having a little trouble figuring out the Trigger for when the Purchase Line field is changed and how to use the Sales Line id field to update the specific Sales Line that matches the id.
field(csg_PoliReceived; Rec.csg_PoliReceived)
{
Caption = 'Purchase Order Line Received';
ApplicationArea = All;
trigger OnValidate()
begin
// if true
// update Sales Line to true
// if false
// update Sales Line to false
end;
}
I have this snippet in a pageextension that extends the Purchase Lines page, so I am not exactly sure how to query for the Sales Line with the matching Id and how to update that record. Any advice would be much appreciated. Thanks!
The modification should be done in the OnValidate trigger of the field on the tableextension you created for Purchase Line.
I am going to assume that you have a field called Sales Line Id which would contain the SystemId of the Sales Line if the Purchase Line is linked to one.
trigger OnValidate()
var
SalesLine: Record "Sales Line";
begin
if not IsNullGuid("Sales Line Id") then begin
SalesLine.GetBySystemId("Sales Line Id");
SalesLine.Validate("Purchase Order Line Received", Received);
SalesLine.Modify(true);
end;
end;
This code will update Purchase Order Line Received on the Sales Line whenever Received is updated on the Purchase Line.
One thing you might want to consider in your design is that a Purchase Line and a Sales Line can be linked in several ways e.g. through reservation or drop shipment.
Related
I currently have a column that is created using the following DAX formula (a calculating language used by platforms such as Power BI) which indicates if the listed activity is the first one ever for that Entity ID. Below is my DAX script if it helps at all:
// "Declares column name"
First Time Activity =
// "if the column 'Timestamp' is equal to..."
if('Activity Table'[Timestamp]=
// "...is equal to the earliest Timestamp for that Entity ID and Activity Name"
CALCULATE(min('Activity Table'[Timestamp]),
filter('Activity Table',
'Activity Table'[Entity ID] = earlier('Activity Table'[Entity ID]) &&
'Activity Table'[Activity Name] = earlier('Activity Table'[Activity Name])
)
)
// "...then return a 1. If not, then return a blank/null"
,1,BLANK())
But I need this now to be a column made in PL SQL rather than in DAX. Any help on the SQL script would be much appreciated since I'm fairly novice at SQL.
Thanks
You don't actually need a column. you can write your query as :
Select a
,decode(activity_date
,MIN(activity_date) over (partition by activity_id)
,'Y'
,'N') first_record_indicator
From activity_table a
But, if you table is too huge to actually query like this everytime, you can create a column named first_record_indicator and populate it in "BEFORE INSERT" trigger.
e.g. https://www.techonthenet.com/oracle/triggers/before_insert.php
In Excel I could, if I was in a table called 'Sales' that had four columns
Sales
Month, CustomerId, ProductId, TotalQuantity
Jan,1, CAR,
Feb,1, CAR,
I could add a formula:
=SUMIFS(Sales[Quantity],Sales[CustomerId],[#[CustomerId]])
That would go to the Sales table and sum the CustomerID column filtered by the CustomerID of the current row where the formula has been entered.
I am attempted to replicate this in a PowerBI Calculated Row but I can't get the # working for a row reference. It comes across like
TotalQuantity = CALCULATE(SUM(Sales[Quantity]),Sales[CustomerId] = Sales[CustomerId]))
Any idea how to get the equivalent # working?
I think the key function you are missing is EARLIER. That is not surprising because it has a misleading name - it really means "Current Row". You also need a FILTER function in the Filter parameter of CALCULATE, to reset the filter context to the entire table.
So your New Column function might look like this:
TotalQuantity = CALCULATE(SUM(Sales[Quantity]), FILTER(Sales, Sales[CustomerId] = EARLIER (Sales[CustomerId])))
Here's a neat example, from the most accessible source site for DAX formulas:
http://www.powerpivotpro.com/2013/07/writing-a-subtotal-calc-column-aka-the-simplest-use-of-the-earlier-function/
And FWIW here is the official doco on EARLIER:
https://msdn.microsoft.com/en-us/library/ee634551.aspx
I have created a new transactions table (tblTransactions) where I can log all my [Debits] (i.e. invoices) and [Credits] (i.e.payments). From this I can run a query with an an expression to get the Current Account Balance.
However, for invoicing purposes, if I pulled the Current Account Balance as described above, it wouldn't be the 'previous account balance' value I want to display to the customer on the invoice, because it's showing a value which includes the current invoice amount. I want the customer to see the previous balance PRIOR TO that invoice.
My current solution uses expressions in a query to calculate this 'previous account balance', but I don't know if could be done another way. Any suggestions on how this could be done better?
I couldn't post a picture of the query b/c I don't have enough reputation points.
Invoice fields I'm trying to populate:
Invoice Amount
Previous Account Balance (prior to this invoice)
Final Invoice Amount
Below are my calculations used in the query
Invoice Amount: Debit
Previous Account Balance: Format([Account Credits]-[Account Debits],"Currency")
Final Invoice Amount: Format([Invoice Amount]-[Previous Account Balance],"Currency")
Account Debits: Format(DSum("[Debit]","tblTransactions","ClientID =" & [ClientID])-[Debit],"Currency")
*This formula takes out the value of the current debit in the query
Account Credits: Format(DSum("[Credit]","tblTransactions","ClientID =" & [ClientID]),"Currency")
A solution "quick and dirty" is to find add a condition to your query excluding the record on which you are working (current invoice).
If you have an ID, you can add a WHERE condition to your DSUM, excluding the current record.
Let's assume IDTransact is ID field of tblTransactions, your WHERE condition should be
"ClientID =" & [ClientID] & "AND IDTransact <> " & CStr([IDTransact])
I assumed the ID is a long (autonumbering).
Hope this can help you.
Let me know.
Bye
I am using PowerBuilder classic 12.5
am having difficulties in inserting, editing, creating and printing reports.
i have a datawindow, dw_NewEmployee with dataobject, d_newrecord which is update-able.
should i use the columns to insert records through the columns or i
create single line texts on the window object
is the itemchanged event used on columns and rows on dataobject or
on single line texts... I am having trouble figuring out how to implement validation rules.
please give me an example to validate employee ID_Number
I see that you seem confused about the datawindow usage.
Let's try to summarize:
you create a new datawindow d_newrecord (say it is a grid) based on a sql select in your database, say select id_number, name from employee.
in the detail zone of the datawindow (that will be repeated for each record at runtime but that is only once in design), you need to put one column object for each column (here you will have id_number and name) these objects are both to display existing data and receive user input for editing data and inserting new records.
don't forget to set the Rows / Update properties if you need to make the dw updatable.
in the header zone of the datawindow you can have a static text associated to each column that is just here to display the column name, it does not concern table data.
in some window object, you place a datawindow control dw_newemployee where the content of the datawindow will be painted, you set d_newrecord as its dataobject.
you need to set at some point the transaction object of the dw, for example in the open() event of the window:
dw_newemployee.SetTransObject(sqlca)
dw_newemployee.Retreive() //if you are using some retreival arguments, don't forget to include them here
When you want to insert new data in your table (for example with a window button "add"), in the clicked() event of the button you call dw_newemployee.InsertRow(0) to insert at the end.
The ItemChanged() event will be triggered after one cell will be modified, you will be given the row, item (a dwobject) and new data. By choosing the returned value of the event, you can accept or reject the new data.
Here is an example for a field validation in itemchanged() event:
long ll_return_code = 0
string ls_column
ls_column = lower(dwo.name)
choose case ls_column
case "id_number"
if long(data) = 42 THEN
messagebox("validation error", "You cannot use 42 for the ID")
ll_return_code = 1 //reject and stay in cell
end if
case "name"
if data = "foobar" then
messagebox("validation error", "Do not use dummy value...")
ll_return_code = 2 //reject but allow to go elsewhere
end if
end choose
return ll_return_code
How do you you display the running GROUP count via SSRS 2005?
I have a report that has n groups where the source data must remain anonymous and I want that number in the header of the group...
So instead of the name in the group header like such...
Employee - John Smith
Employee - Mary Swain
...
Employee - Ahmad Sal
I want...
Employee #1
Employee #2
...
Employee #n
Thanks!!!
=RunningValue(Fields!Employee.Value, CountDistinct, Nothing)
Voila!
Use
RowNumber("table1_Group1")
I know this is super old, but I'm sharing this for anyone having the same problem.
It depends on your table and the level of grouping. For example, let's say I have a Details group and two parent groups called "Parent" and "Child".
Parent{
Child{
Details group{
Using just the "RowNumber" function will only return records from a Details group, not from a Row Group. Riegardt was very close, however, even this doesn't account for the level of grouping or null ("Nothing").
If this was to be applied to the group called "Child" in the structure I mentioned above, this wouldn't work.
Also, The count would potentially be inconsistent if there were records in the column with a null ("Nothing") value.
"Count" and "CountDistinct" start their count at zero for null values and one for non-null values (this applies to the "RunningValue" function's parameter as well).
The solution is to include ALL parent groups above the current group you're counting and to not even allow the value from a column to return null in the first place. Here's my solution:
Row Groups within a parent Group:
=RunningValue(IIf(IsNothing(Fields!ParentFieldValue.Value), "", Fields!ParentFieldValue.Value).ToString & IIf(IsNothing(Fields!ChildFieldValue.Value), "", Fields!ChildFieldValue.Value).ToString, CountDistinct, Nothing)
Row Groups with no parent Group:
=RunningValue(IIf(IsNothing(Fields!ParentFieldValue.Value), "", Fields!ParentFieldValue.Value).ToString, CountDistinct, Nothing)
OK, I have a workaround that only is valid because the number of rows is constant for each group.
=(RowNumber("table2"))/(RowNumber("table2_Group1"))
This will work for the scope of this report, but it still seems like there should be an easier way...