Get latest date in a column based on a duplicate value in a table using Powerautomate - azure-logic-apps

I have a table in dataverse, that has a date, telephone number, and ID columns as below.
Date
ID
Telnum
12/6/202
abcd
8421678
12/9/2020
abce
8421679
12/13/2020
abcg
8421678
From the table the 1st and 3rd column have the same Tel num, but different dates and ID. What am trying to achieve is on the same table in a column called end date,post the last date with regards to the tel num this is basically the 1st date of the date the number switched to a new record based on ID.
The table am trying to come up with looks as below
Date
ID
Telnum
Date To
12/6/202
abcd
8421678
12/13/2020
12/9/2020
abce
8421679
12/13/2020
abcg
8421678
What I've tried is create an Instant flow, List Records(The table name), List records 2 (Table name but this tome with filters {The filters are (tel num eq tel num and id ne id)}, Then Update record to populate the end date.
What am missing is a step to get the max or latest date of the column that I will append to the date to mapping.
Any idea on how to achieve this will be highly appreciated.
TIA.

According to the description of your requirement, it seems you want to add one more column(named Date To) for the table and set the current date(you mentioned as max or latest date) as the value of the new column.
The second table you provide shows the value of DateTo should be like 12/13/2020, but if you just set the date with the format month/day/year, it can't help you distinguish the two records which has same Telnum because they are both 12/13/2020. So you should set the value of DateTo with format of 2020-12-21T07:23:34.5951356Z. To implement it, you can use utcNow() method shown like below screenshot.
If I misunderstand your requirement, please let me know and provide more details about your question.

Related

Power Query Calendar

I am trying to create a calendar using Power Query functions and for that I used below syntax in blank query:
Source= Duration.TotalDays(DateTime.LocalNow() - #datetime(2014,01,01,00,00,00)) * 24
Date= List.DateTimes(#datetime(2014,01,01,00,00,00), Source ,#duration(0,1,0,0))
Then I convert to a table and apply query.
Connect dimension date table to date column in fact table.
 
The error occurs when I’m trying to mark table as date table:
‘The date column can only gave one timestamp per day. The date column
can’t have gaps in dates’
 
What I have done wrong?
As the error message says:
The date column can only have one timestamp per day.
While you are trying to add 24, one for each hour. See the requirements for setting a table as a date table:
if it is a Date/Time data type, it has the same timestamp across each value
i.e. you can have only one value for each date, and if it is not a date, but datetime value, all time values should be the same.

How can select 2 records for each id from a table.?

How to select two records from multiple records first where the date field is minimum and second where the date field is maximum.
I will try to explain you in brief:- I have a records_history table where there can be multiple records for one Employee. I want to select only two records for one employee based on max and minimum date . How can i achieve this?
Currently what is done for this scenario is first select all records from Employee then stored it into a temp table the apply cursor for the temp table and get the distinct employee record and then they are selecting the max and min data records from the temp table. but it is taking to much time for processing.
Please suggest a way out for this problem.?
As I can understand you want max and min value for one column based on employee ID.
Select max(column_name) as 'Max', min(column_name) as 'Mini' from table_name group by EmployeeID having EmployeeID='EmployeeID'
Please accept the answer if it helps

Query date ranges between two fields

I need to select from a table that has two fields , a start date and an end date , selecting the row that the current date is. Look at the image ...how do i select the row that encompasses the date range 91/201 - 9/15/2018 ? Somehow this was flagged as a duplicate. I am NOT attempting to find overlap. I am attempting to find the row that represents a given date. Say , one table has a field that has the value 9/5/2018 ....how do I select the row that has a start date of 9/1/2018 and end date of 9/15/2018

Date range based on Column Date

I am using the latest SQL Server. I have a table with a CreatedDate column. I need to write a Query that uses dates that are plus or minus 7 from the Date in CreatedDate. I have no clue how to go about this. My thought was this:
DECLARE #Date datetime
DECLARE #SevenBefore datetime
DECLARE #SevenAfter datetime
SET #Date = CreatedDate
SET #SevenBefore = DATEADD(day,-7,#Date)
SET #SevenAfter = DATEADD(day,7,#Date)
SELECT *
FROM <table>
WHERE <table> BETWEEN #SevenBefore AND #SevenAfter
The issue with this is that I cannot use "CreatedDate" as a SET #DATE because SQL gives an error "Invalid column name 'CreatedDate'"
Any help would be appreciated. I cannot list a date because every date in that column could be different.
Thanks
In this case, you need to stop thinking as a programmer would, and start thinking as a Database programmer would.
Lets work only with this central part of your query:
SELECT *
FROM <table>
WHERE <table> BETWEEN #SevenBefore AND #SevenAfter
Now, you say that the CreatedDate is a column in a table. For this example, I will assume that the CreatedDate is in a table other than the one in your example above. For this purpose, I will give two fake names to the tables. The table with the CreatedDate, I will call tblCreated, and the one from the query above I will call tblData.
Looking above, it's pretty obvious that you can't compare an entire table row to a date. There must be a field in that table that contains a date/time value. I will call this column TargetDate.
Given these assumptions, your query would look something like:
SELECT *
FROM tblCreated tc
INNER JOIN tblData td
ON td.TargetDate BETWEEN DATEADD(day, -7, tc.CreatedDate) and DATEADD(day, 7, tc.CreatedDate)
Looking at this, it is clear that you still need some other associations between the tables. Do you only want all data rows per customer based on the Created date, or perhaps only want Creations where some work was done on them as shown in the Data records, or ??. Without a fuller specification, we can't help with that, though.

How to Select values from relevent specific month in date type?

Im new to msSql and i have a set of data about persons. and i need to get results of persons who has birthday in February month.
my DOB fields shows YYYY-MM-DD (1990-02-25)
Can some one please help me to get this results ?
Try like this,
SELECT *FROM
<TableName>
WHERE month(YourDateColumName)=2

Resources