Redshift query not returning certain columns - amazon-web-services

I have encountered a strange error on on of our tables ("nav") with the following structure:
position | character varying(400)
timestamp | timestamp without time zone
If I run the following query, I get back, as expected, all matching results for the 2 columns:
SELECT * FROM nav WHERE timestamp >= '2019-03-24' AND timestamp < '2019-03-25';
However, if I run the following query, I get back the same number of results, but each field/row is empty:
SELECT position FROM nav WHERE timestamp >= '2019-03-24' AND timestamp < '2019-03-25';
I run the same query on similar tables and experience no issues. Any ideas as to what may be causing the second to return blanks in the rows please?

Related

Column does not exist AWS Timestream Query error

I am trying to apply WHERE clause on DIMENSION of the AWS Timestream records. However, I got the error: Column does not exist
Here is my table schema:
The table schema
The table measure
First, I will show all the sample data I put in the table
SELECT username, time, manual_usage
FROM "meter-reading"."meter-metrics"
ORDER BY time DESC
LIMIT 4
The result:
Result
What I wanted to do is to query and filter the records by the Dimension ("username" specifically).
SELECT *
FROM "meter-reading"."meter-metrics"
WHERE measure_name = "OnceADay"
ORDER BY time DESC LIMIT 10
Then I got the Error: Column 'OnceADay' does not exist
I tried to search for any quotas for Dimensions name and check for error in my schema:
https://docs.aws.amazon.com/timestream/latest/developerguide/ts-limits.html#limits.naming
https://docs.aws.amazon.com/timestream/latest/developerguide/ts-limits.html#limits.system_identifier
But I didn't find that my "username" for the dimension violate any of the above rules.
I checked for some other queries by AWS Blog, the author used the WHERE clause for the Dimension filter normally:
https://aws.amazon.com/blogs/database/effective-queries-for-common-query-patterns-in-amazon-timestream/
I figured it out after I tried with the sample code. Turn out it was a silly mistake I believe.
Using apostrophe (') instead of single quotation marks ("") solved my problem.
SELECT *
FROM "meter-reading"."meter-metrics"
WHERE username = 'OnceADay'
ORDER BY time DESC LIMIT 10

PowerBi Dax - Create a Measure that ignores applied filters and display in barchart

In my data I have two columns of date - claim registration date and resolved date. My report is using resolved date as a slicer filter. I would like to build a bar chart showing registered claims by client segments. I have tried several approaches and functions but they all return single count value. What I want is actual counted values for each type.
BySegmentRegistered = CALCULATE(COUNT(claims_data[client_id]),claims_data[reg_date].[MonthNo] == MONTH(SELECTEDVALUE(DateTable[MonthYear])),ALL(claims_data))
BySegmentRegistered = CALCULATE(COUNT(claims_data[client_id]),FILTER(ALL(claims_data),claims_data[reg_date].[MonthNo] == MONTH(SELECTEDVALUE(DateTable[MonthYear]))))
I have tried above code and several other iterations but they all return single value across all client_segments. If I simply do COUNT(claims_data[client_id]) than it displays count by each segment but date is wrong, hence it doesnt work for me.
Any ideas?
EDIT:
I just tried this and it works.
BySegmentRegistered = CALCULATE(COUNT(claims_data[cliend_id]), claims_data[reg_date].[MonthNo] == MONTH(SELECTEDVALUE(DateTable[MonthYear])), REMOVEFILTERS(DateTable[MonthYear]))

Expression Error Key didn't Match Any Rows

I am trying to get today's current date and format it to yymmdd because my table name change daily. e.g. MICRINFO210616 and tomorrow it will be MICRINFO210617
When I run thecode below I get the following error:
Expression.Error: The key didn't match any rows in the table.
Key=
Schema=dbo
Item=MICRINFO210617
Table=[Table]
code:
let
Source = Sql.Database("TEST", "TEST"),
formattedDate = Date.ToText(DateTime.Date(DateTime.LocalNow()), "yyMMdd"),
combine = "MICRINFO" & formattedDate,
dbo_MICRINFO210616 = Source{[Schema="dbo", Item=combine]}[Data]
in
dbo_MICRINFO210616
Make sure the account you're using has at least read permissions (to the new table).
Check if the structure of both tables is the same (same number of columns, same datatype).

Filter a date by current date in PowerQuery / PowerBI

I'm creating a report in PowerBI, and need to filter out some erroneous record from my source. Its a payment table, and some records are with a future date, eg in 2799. I'd like to make a Filter to remove records after today + 1 year. I already had this filter :
= Table.SelectRows(_cobranca, each [Vencimento] >= DATA_LIMITE)
DATA_LIMITE is a parameter, and the code above is already working. I tried to change it to :
= Table.SelectRows(_cobranca, each [Vencimento] >= DATA_LIMITE and [Vencimento] <= DateTime.LocalNow())
But I'm getting this error:
DataFormat.Error: Syntax error in date in query expression '[_].[Vencimento] >= #2020-01-01 00:00:00# and [_].[Vencimento] <= #2020-10-21 10:58:07.4411693'.
It seems that DateTime.LocaNow function is not returning the date in the correct format.
Replace DateTime.LocalNow() with Date.From(DateTime.LocalNow()) as I assume your [Vencimento] column (due date?) is just a date data type not date time

Trying to get the time delta between two date columns in a dataframe, where one column can possibly be "NaT"

I am trying to get the difference in days between two dates pulled from a SQL database. One is the start date, the other is a completed date. The completed date can and is, in this case, be a NaT value. Essentially I'd like to iterate through each row, and take the difference, if the completed date is NaT I'd like to skip it or assign a NaN value, in a completely new delta column. the code below is giving me this error: 'member_descriptor' object is not callable
for n in df.FINAL_DATE:
df.DELTA = [0]
if n is None:
df.DELTA = None
break
else:
df.DELTA = datetime.timedelta.days(df['FINAL_DATE'], df['START_DATE'])
So, you first have to check if any of the dates are NaT. If not, you can calculate by:
df.DELTA = (df['FINAL_DATE'] - df['START_DATE']).days