Unlock a world of possibilities! Login now and discover the exclusive benefits awaiting you.
I need to filter a table on Qlik Cloud and then retrieve the data using GetHyperCubeDataAsync. The filter works correctly when I apply it to a string column, but it doesn't work when I try to apply it to the 'Inizio' column, which is a date. What am I doing wrong? Thanks
IQcsLocation location = QcsLocation.FromUri(qlikApiUrl);
location.AsApiKey(qlikApiKey);
using (IApp app = location.App(qlikAppId))
{
//string identifFilter = "2-7-1-12-30";
DateTime dateTime = new DateTime(2023, 6, 13, 10, 40, 42, DateTimeKind.Utc);
//var identifField = app.GetField("Identificativo");
// Applica i filtri sulle date
var inizioField = app.GetField("Inizio");
var fineField = app.GetField("Fine");
// Converti le date nel formato richiesto
DateTime dataInizio = DateTime.ParseExact(dataInizioFilter, "M/d/yyyy h:mm:ss tt", CultureInfo.InvariantCulture);
//DateTime dataFine = DateTime.ParseExact(dataFineFilter, "M/d/yyyy", CultureInfo.InvariantCulture);
var inizioFieldValues = new List<FieldValue>
{
new FieldValue{ IsNumeric = true, Number = dateTime.ToOADate() }
};
inizioField.SelectValues(inizioFieldValues.ToArray(), true);
}
This is my qlik table:
Matching on float point values is always tricky. Are you sure there is not a millisecond part to those timestamp that you miss? The string formatting of timestamps often hides that part. And also, I'm not sure if the C# "ToOADate" produces the number in the format that Qlik uses, but perhaps you've already verified that.
You could potentially do a match based on the string representation of the timestamp. You already seem to have the "dataInzioFilter" available. With that you should be able to do something like this:
inzioField.Select(dataInzioFilter);
Matching on float point values is always tricky. Are you sure there is not a millisecond part to those timestamp that you miss? The string formatting of timestamps often hides that part. And also, I'm not sure if the C# "ToOADate" produces the number in the format that Qlik uses, but perhaps you've already verified that.
You could potentially do a match based on the string representation of the timestamp. You already seem to have the "dataInzioFilter" available. With that you should be able to do something like this:
inzioField.Select(dataInzioFilter);
ok thanks,
How do I filter the field within a date range instead? I tried this way but it doesn't work:
var fineField = app.GetField("Fine");
//var competenzaField = app.GetField("Gestione di Competenza");
//var fineField = app.GetField("Fine");
if (!string.IsNullOrWhiteSpace(dataInizioFilter))
{
try
{
DateTime dataInizio = DateTime.ParseExact(dataInizioFilter, "dd/MM/yyyy HH:mm", CultureInfo.InvariantCulture);
DateTime dataFine = DateTime.ParseExact(dataFineFilter, "dd/MM/yyyy HH:mm", CultureInfo.InvariantCulture);
//inizioField.Select(dataInizioFilter);
// Applica il filtro sulla colonna "Fine"
//string dateFilterExpression = $"=[Fine] >= '{dataInizio:yyyy-MM-dd}' AND [Fine] <= '{dataFine:yyyy-MM-dd}'";
string dateFilterExpression = $"=[Fine] >= '{dataInizio:dd/MM/yyyy HH:mm}' AND [Fine] <= '{dataFine:dd/MM/yyyy HH:mm}'";
fineField.Select(dateFilterExpression);
//fineField.SelectValues(dataInizio, dataFine);
}
catch
{
return req.CreateResponse(HttpStatusCode.BadRequest, "Data Inizio non valida");
}
}