Retrieving previous value in Mongodb query - sql

I am trying to retrieve a previous value and create a new column called previous_values next to the current values and group them by their id's so tht previous_values do not get mixed. However, I am not able to perform lead and lag operations on Mongodb query like I did in Postgresql. Can someone help? My table is shown below. enter image description here

Related

Represent SQL Server table data in Power BI dektop table but with one extra column

I have a table in SQL Server that contains document-related data. Data entry in this table is handled from ASP.NET code:
I have to show this table data in PowerBI desktop. With normal Select query I could bind the data in table of Power BI desktop. But along with this table data I have to show one more column IsProcessedBefore which I have to compute for each row.
This column values could be '1' or '0':
1 indicates that this particular Document Number has been processed earlier
0 indicates that this particular Document Number has not been processed earlier.
Output should be shown in Power BI desktop report as shown below.
I am not getting how could I compute this indicator for already existing data.
Whenever a new entry is done in the SQL Server table. It must be reflected same in the PowerBI report along with the computed indicator value.
Please help me with this scenario.
One way that I found is to create another page in same Power BI report, showing the number of times the documents processed using group by query on documentnumber and documentId (Output Shown below). But this is just workaround. Using this approach we will be having two pages. One could check documentnumber from actual table data in below output and refer its count. If its count is greater than 1 that means it is processed earlier.
.
But this workaround does not match up with the exact requirement.

Can I make an interactive filter in SQL?

I am using SQL in DashBuilder and want to make a statement in SQL that will display one column of data (month). Then when the user clicks on a row in that column of data that table will display the rest of the columns filtered on that entry (a specific month) to only show data from that month. Is this possible in SQL?
I can filter in SQL without a problem but am unsure if interactive filtering is possible or if I need to use another feature of DashBuilder to do so.

Pentaho compare values from table to a number from REST api

I need to make a dimension for a datawarehouse using pentaho.
I need to compare a number in a table with the number I get from a REST call.
If the number is not in the table, I need to set it to a default (999). I was thinking to use table input step with a select statement, and a javascript step that if the result is null to set it to 999. The problem is if there is no result, there is nothing passed through. How can this be done? Another idea was to get all values from that table and somehow convert it to something so I can read id as an array in javascript. I'm very new to pentaho DI but I've did some research but couldn't find what I was looking for. Anyone know how to solve this? If you need information, or want to see my transformation let me know!
Steps something like this:
Load number from api
Get Numbers from table
A) If number not in table -> set number to value 999
B) If number is in table -> do nothing
Continue with transformation with that number
I have this atm:
But the problem is if the number is not in the table, it returns nothing. I was trying to check in javascript if number = null or 0 then set it to 999.
Thanks in advance!
Replace the Input rain-type table by a lookup stream.
You read the main input with a rest, and the dimension table with an Input table, then make a Stream Lookup in which you specify that the lookup step is the dimension input table. In this step you can also specify a default value of 999.
The lookup stream works like this: for each row coming in from the main stream, the steps looks if it exists in the reference step and adds the reference fields to the row. So there is always one and exactly one passing by.

Trying to count records in SSRS from different data sets

I have an SSRS report that combines 5 reports into one. Each report is populated from a different stored procedure. The first page is a summary that is to provide a record count from each report. I've created fields in the stored procedure that provides the counts for each individual report: phycount and nonphyscount. I'm trying to create a table similar to this:
Active comes from one data set, Initial comes from another, Recert comes from another, etc.
I've been playing around with the Lookup and LookupSet but I'm just getting errors, plus I'm not sure if that's even the right direction.
Does anyone know how to do this?
Lookup and Lookupset are more for getting specific values out of a dataset. Very useful but not necessary for what you're trying to accomplish.
You can use aggregate functions SUM and COUNT to accomplish what you want to do. The cool thing about these functions is you can actually embed IIF statements inside of them.
I'm not sure exactly how your datasets look and are named but it would be something like this...
SUM(IIF(Fields!Type.Value = "PhyCount", 1, 0), "Active")
The sum function goes through every row of your dataset and sums the values you pass to it. The iif statement checks to see if the type field in the dataset is "PhyCount". If so, it returns 1, if not, 0. Since this will happen for every row, your SUM function will return a count of each row with status active.
edit: "Active" after the iif statement specifies the name of the dataset.
EDIT AGAIN: This solution apparently does not work in SSRS 2008.

Create table without omitting empty rows?

I have a short question but no reproducible sample as I simply use the standard function for now.
I want to use SQL's CREATE TABLE function. However, I want the table to display rows even if there are no data points for that specific ovbservation. Currently, whenever there is no data for a certain row, the whole row gets omitted. Ideally I'd like it to still display the row for that specific date, and just have empty cells wher ethe data is missing.
This is important because I need the table to be of specific size, even if data is missing.
One idea I had was to include a WHERE ROWNUM statement, which refers to a materialised view or table of exactly the size I want the table to be in. Is this possible? Any other solution is welcome.
Create table first of all.
use insert statement to insert all the required rows at once (empty rows with only date, or rowindex)
'View' idea is not better, because you have to show those record (empty rows to enter data perhaps) to user, so if user enters data in 5th rows, you will not be able to add 5th row in table prior to first 4 rows.