Read data that is already in output and write back to the output - palantir-foundry

I have requirement to read the data that is already in the output and join the data to input and write back the data to the same output. This build is scheduled every day.
Input:
ID
Refresh_Date
1
6/8/2022
2
6/8/2022
3
6/8/2022
Historical(Output):
ID
Order Date
Order Closure
Age
1
6/6/2022
6/7/2022
1
2
6/7/2022
3
6/7/2022
4
6/7/2022
The input data will be refreshed with new orders every day, so I have join the input to the historical data and find the closure date and time it took to close the order.
The result of the join should be saved as Historical again
I tried using incremental computation but the output in read mode is always giving me empty dataset.

Your intuition to use #incremental decorator is correct.
It sounds like your problem is related to the mode in which you are accessing the current dataframe. Check out the documentation on incremental modes of inputs and outputs; in particular, the default mode is added while you'd probably want to use current or previous for your implementation, as these are the modes that give you access to the data currently within the dataset.
Also, the documentation on incremental decorator is overall very helpful to understand how to make incremental computation work for you. Have a look at different parameters you can pass to your decorator, in particular snapshot_inputs, as it may affect how you access the input dataset as well.

Related

Trying to pull Max date less than Date on the row

I know this is a tough one but I'm basically trying to say. Give me a service call and its completion date, then give me the Max date for all service calls where the date is less than the date of the service call I'm inquiring about.
Basically the end result I'm looking for is to say was there another service call on this piece of equipment that was within the last 30 days.
So as you can see in the image for say Asset 50698 service call 579032 we have a date of 11/9/2020 the call below that was 10/22/2020 which was less than 30 days. I want to somehow find a way to count how many service calls I have where this has occurred. Is this possible?
I think you're looking for a context operator In, ForEach or ForAll (in in this case)
Add a variable "MaxAssetDate" and assign it a Formula similar to the following based on your column headers.
=Max([Service Call Completion Date] In ([Asset ID];[Service Call])) In (Asset ID])
Then add this as a column. Provided you have a prompt filtering for a given asset or "date" this column will then show the max date for each service call of the same asset ID. Then add a new variable: ServiceCallDaysDiff: Then by using DatesBetween() with "MaxAssetDate" and ServiceCallCompletionDate and DayPeriod; =DatesBetween([ServiceCallCompletionDate];[MaxAssetDate];DayPeriod) you should get a number 0-X. Then add a filter based if the number is between 1 and 30 then you show those records, otherwise hide the rest; or do whatever logic is then needed.
Now if you're dealing with hundreds of thousands of records this isn't ideal as you're putting all the processing on the webi engine when it ideally would occur as an object in the database layer. However if you only have a few thousand records this should be managable.
To add a count of service calls...
add variable: ServiceCallsCount:
=Sum(Sum(If([ServiceCallDaysDiff]=0;0;1)) In ([AssetID]))
this will count the non zero day differents. Note this will extend beyond 30 so if you want to limit by 30 days adjust the if statement to zero out those not between 1 and 30.
This is but one approach: there may be simpler ways.

Filter data set by month

I'm using an embedded data source of type SharePoint List.
I use a parameter that a user can modify that will filter the data set by the month. I've seen a few examples but they all either use a SQL query or only filters on the exact day rather than the month.
I added a parameter ParamMonth and gave it the data type of Date/Time. I can see this adds a drop down box to my report which is exactly what I want. Ideally, I would like to add the name of all 12 months or something similar, but I don't know how that will work out when the data exceeds a single year. Now, that I've got my Report Parameter added, I need to add it to my dataset to filter on. This is where I'm stuck.
An easy way could be creating a parameter type Integer and set all months in Available Values tab as follows (I just set five months for example).
Then go to the DataSet Properties / Filter tab and use the below settings.
For expression use:
=MONTH(Fields!Date.Value)
Where Date is the field that you will use to filter by month. In Value you have to use:
=Parameters!Month.Value
UPDATE: Provide year selection.
The best approach for this is getting the available values from a DataSet, in this case your SP list.
Just create a calculated field in your dataset with available years (it can be a copy of the SP list dataset), call it calculatedYear and use:
=YEAR(Fields!Date.Value)
Now create a Year parameter of Intenger data type, and set this settings:
Where DataSet15 is the DataSet name that feeds your parameter with the available years.
Then just add another filter in your dataset:
Note you will need two datasets one to get the available years and
other the dataset you need to filter.
Let me know if this helps.

What ID does a ComboBox reference?

I am attempting to maintain and fix a horribly out-of-date CRM designed by an ex-employee ~4-5 years ago in Access 2007. I have brought it into Access 2013 and fixed a ton of stuff up, but I am still running into many problems.
I spent a good 4 hours today attempting to figure out why certain values didn't line up. These values were being pulled from a SELECT statement on a Combo Box over a stored Query which simply returns a table with a few extra rows. Great.
However this value (a number) doesn't appear to correlate with what we expect. I enter in one value, save the ticket, and a completely different value gets stored into the table. Opening up the ticket, I see the value that I expect. Digging deeper, I found the following difference:
Set value_1 = Me.RegistrationID // What's being stored in the table
Set value_2 = Me.RegistrationID.Column(0) // What we expect
Surprise surprise! This is a Combo Box and some value is being stored in the table. The Control Source is "RegistrationID" and the Row Source is the query in question.
However I do not know what it is! This specific value correlating to the Combo Box appears to pull the correct data when we later open the tickets. However I have a strong feeling that this could be why many tickets from before one of the rows was deleted all appear to have invalid RegistrationID's.
How badly can this break?
How easily can we correct tens of thousands of tickets?
How can I fix this to store the correct value?
This is what I expect is happening.
Your combo box row source is based on a Select query which returns and displays multiple rows. For example:
Select RegistrationID, CustomerID, CustomerName From MyTable;
The Control Source for the combo box is bound to RegistrationID which is part of the Forms Record Source.
The issue is the bound column. If we set the bound column in our example to 1, then we get the behavior your are describing with:
Set value_1 = Me.RegistrationID - Set's value to CustomerID (may appear correct)
Set value_2 = Me.RegistrationID.Column(0) - position 0 from our query (RegistrationID)
Further building on our query example, you can say:
Me.TextBox1 = Me.RegistrationID.Column(0) - RegistrationID
Me.TextBox2 = Me.RegistrationID.Column(1) - CustomerID
Me.TextBox3 = Me.RegistrationID.Column(2) - CustomerName
The RegistrationID is what normally should be stored in the table.
As long as your form shows any values that directly relate to this RegistrationID you're fine.
I would start by checking to see under the format setting to see if column widths are set properly and I would also check under the data section to see if the bound column is correct. I might also throw in an after update macro/vba sub routine that saves the record. Hope this helps.

MS-Access Web DB "type mismatch" when setting date as string?

This is specifically for MS-Access Web Databases (requires Sharepoint hosting) which has many limitations compared to their client counterparts, like no VBA, instead you get form macros and data macros to manage data.
I've run into a weird bug on one of my applications. I have a query used to check stock levels against a "minimum stock level" also saved in the table. The query is pretty intense and there are over 4,000 records now to check against. These querys normally take about 75s. So I have made a little label that gets updated every time the form is loaded showing the time and date the query was last run, and the duration in seconds it took. (so users can see how fresh the data is and decide if it needs to be run again)
Now, the weird thing is it works fine in my Access client, but when I sync my changes to the server and try it in a web browser I get a "type mismatch" error. A small table is used to store the start and end times whenever the query is run, that's how I get the timestamp data. These fields are in a "Date/Time" format, obviously. But it seems the problem here is changing the date format to a string format so it can be put in a label on the form. The Access client seems perfectly capable of doing this, while the web client stumbles and falls.
My problem is, how do I change data in a date/time format to a string format in a Web database? I can't figure out how to do this. The tools are so limited. I may have to end up answering my own question here but I'm posting this for others just in case.
To return a value from a data macro as string, you have to format the internal date/time format as a string. In Access an internal date/time value is a double number with the integer part as number of days since 1900, and the “decimal” time part is a fraction of 24 hours. Unfortunately if you simply wrap the date/time in the str$() function we had for 20+ years, then you get something JUST like if you type this into the debug window:
? cdbl(now())
41955.5478587963
The solution is to simply pull out each part. And “nice” is while in few cases a data macro will cast the data type, it does in this case and thus the STR$() command is not required.
The expression you thus can use is this:
Month([d]) & "/" & Day([d]) & " Time = " & Hour([d]) & ":" & Minute([d])
So say to pluck out the VERY LAST start time column from say a invoice table, since we don’t have a dmax(), then we simply sort the table in the order we want and pull out the first row.
Our data macro will thus look like:
Note how in above I simply typed in the SQL and SET the order on the date/time column. I want the MOST recent invoice start date and time. For those new to SQL, then I suggest you build a query in the query builder and specify a query in above lookup feature, since many are not "comfortable" typing in free hand SQL as I did above.
Now, in your browser side (UI) macro, you can use this code:
The above returns a formatted string that you can stuff into a text box, or as per above code change the caption of a label.
Unfortunately with silly problems like this, it becomes a path-of-least resistance thing.
Since my intended result was simply to get "a timedatestamp from a table to show up on a form (so users could see when a query was last run)", this became redesigning my form in Access to be a text field instead of a label. Text fields can be adjusted to accept "Time/Date" formats, so this is exactly what I did, it now pulls the timestamp data directly from the last record of the table and requires no extra formatting to appear in the web browser. I redesigned the text field to appear and function more like a label, and my desired function was achieved.
However, since my question specifically asks, "how do you change a time/date format into a string format in a Web db?", I will leave it here in case someone actually does solve it.

Dynamic Sequencing of data in MS Access Reports

So, I have this Report:
And this Query:
The report pulls all of it's data from the query. The fields STA1, STA2, STA3, and STA4 are from the Job Order table in which each job has an order set based on Work Stations (Named CU01, CU02, BR01...).
I have attempted to make macros that essentially say
If Reports![Production Router LBPW]![Work Station 1]="CU01" Then Reports![Production Router LBPW]![Run Time 1]=Query![Query Laser Hours by P/N]![Total Laser Hours]
If I understand properly, a series of statements like that could essentially associate each work station with a specific type of time data (Cutting, Bending, Inserting, and Welding), effectively rearranging my fields to automatically display the time data I want in the places I want them. Alas, I don't know enough about macros to make that work and I know even less about VBA. If I can be filled in on a couple lines of code, or something, that would allow me to accomplish this, I'm sure I may be able to figure it out from there.
One approach would be to create various queries, for example:
QueryCU01
SELECT [Cuttime] As Pos1, [Weldtime] As Pos2, [Rivettime] As Pos3, Bend As Pos4
FROM JobOrder
You report would then refer to Pos1, not CutTime. The labels could also be textboxes, so they update automatically as well, for example:
SELECT [Cuttime] As Pos1, "Cut" As lbl1, [Weldtime] As Pos2, "Weld" As lbl2
[Rivettime] As Pos3, "Rivet" As lbl3, Bend As Pos4 "Bend" As lbl4
FROM JobOrder
It is possible that you could simplify further by normalizing your tables.
Tasks table
Job Action Time Machine SortOrder
1 Cut 10 AB 3
1 Bend 4 CD 1
1 Rivet 30 EF 6
So, what I've done is use a series of Switch functions in my query so that the data that is pulled into each query is inserted into each field by a logical statement. For operation name, the logic is as follows:
OP2: Switch([ST2]="PE01","Insert",[ST2]="PE02","Insert",[ST2]="BR01","Bend",[ST2]="BR02","Bend",[ST2]="WE01","Auto Weld",[ST2]="WE02","MIG Weld",[ST2]="WE03","TIG Weld",True,"N/A")
Which essentially means, If ST2=PE01, Then OP2=Insert, elseif ST2=BR01, then OP2=Bend...
Then I set up another swith that says If OP2=Bend, Time2=BendTime... So on and so forth. This way each field contains a value that is entered based on the logical statements and the order of the jobs is determined by the order that I've set when I enterred the station names in the Job Order Table.