JQL - How to query for a list of epics and all its children issues when epics' due date = xxx? - jql

How to query for a list of epics and all its children issues when epics' due date is within a range and epics' due date is under a structure?
I have a query like this but it does not return children issues that do not have a due date or their due date is not within a range. I need all the issues as long as they are children of a list of epics where the epics meet certain criteria.
type not in (Milestone, Deliverable, Requirement)
AND due >= 2022-07-01
AND due <= 2022-09-30
AND issue in structure(2607, xxx-3546)

Related

CAST and CONVERT both failing when attempting to convert string to date

I'm dealing with a table containing records from questionnaires administered to people after completing an activity. There are several questions on the questionnaire, so each person has multiple records with the same collection date, like so.
PersonID Question Result CollectedDate
-------------------------------------------------------------
1001 First activity? Yes 10/23/2022
1001 Activity date 10/20/2022 10/23/2022
1001 Activity type Painting 10/23/2022
1002 First activity? No 10/24/2022
1002 Activity date 10/23/2022 10/24/2022
1002 Activity type Writing 10/24/2022
Since my end goal is to compare the activity date with the questionnaire collection date and see how much time elapsed between them, I've altered my query a bit so I'm focusing only on each person's question regarding the activity date. It's a super simple query:
SELECT
PersonID,
Question,
Result,
CollectedDate
FROM Questionnaire
WHERE Question LIKE '%date%'
PersonID Question Result CollectedDate
-------------------------------------------------------------
1001 Activity date 10/20/2022 10/23/2022
1002 Activity date 10/23/2022 10/24/2022
My main issue is that the Result field is varchar(50) in order to accommodate text answers, so any dates seen there are actually from free text fields in the front-end interface. I've tried using both CAST() and CONVERT() to turn it into an actual date format so the difference between the dates can be calculated. I've seen both of the following errors depending on which function I'm using or which date/time style I'm attempting to apply:
Conversion failed when converting date and/or time from character string
The conversion of a varchar data type to a datetime data type resulted in an out-of-range value
I've tried:
SELECT
PersonID,
Question,
CAST(Result as date),
CollectedDate
FROM Questionnaire
WHERE Question LIKE '%date%'
and...
SELECT
PersonID,
Question,
CONVERT(DATETIME,Result,101) as Result,
CollectedDate
FROM Questionnaire
WHERE Question LIKE '%date%'
...and have tried several different styles. Does anyone have any further suggestions? Is the date itself likely the problem, or is if the fact that the Result field contains a bunch of other stuff too, even though it's currently omitted from the query results?
UPDATE: There are some kind of wonky date formats in this Result field even when I have the other question types filtered out (I hate free text). For example, there are some formatted like 05/01/2022 and others like 5/1/2022. Some others have something like 5/19/2022 - 5/20/2022, like maybe the person couldn't remember the exact date of their activity. What's the best way to deal with all of this?
You should be able to get past the error by making sure you reject any value that can't be converted to a date. Largely, that is this:
Result = CASE
WHEN ISDATE(Result) = 1 THEN CONVERT(date, Result, 101) END
You'd think it would be enough to say WHERE Question = 'Activity Date' AND ISDATE(Result) = 1, but:
Someone still might have entered bad data on that row.
SQL Server might try to perform the CONVERT() operation before the filter.
You can identify the ones that have bad data using:
WHERE Question = 'Activity Date' AND ISDATE(Result) = 0
But until you've fixed the structure and stored dates in an independent column, fixing that data just means it's a matter of time before it happens again.
You might consider, in the meantime, just displaying what the user entered as a string, instead of trying to force it to be converted to a date. Especially since 101 might be a bad guess - what if the user is from the UK or Canada? They may have entered 05/12 and meant December 5th, not May 12th.

SSAS Date stored as text

I have a measure table for forecast that has a MMM-YY date stored as text;
Period Forecast
-------------------
Jan-20 200
Feb-20 300
I also have some other tables in my model that have similar date formats ie. (1/2020) or 2020_1. Hence I created a date dimension that maps the period to an actual datetime and linked it to the fact table;
Period (Month/Year) Year_Month MonthEnd
---------------------------------------------------
Jan-20 (1/2020) 2020_1 31/01/2020
Feb-20 (2/2020) 2020_2 28/02/2020
This is causing me two issues;
If I slice the forecast by period I get the right answer, but if I slice by the datetime field 'MonthEnd', SSAS can't allocate the costs across the attributes and I get the total each month (so 500 in both jan and feb in this example). Why?
I can't connect time as a referenced dimension to the date dimension so I can't use any time intelligence features.
I could just swap the period ID for a datetime on ETL to standardise the date fields across the model, but I wondered if there was a standard way to approach this?
https://imgur.com/gallery/onxtvhq
In Analysis Services Multidimensional models you need to standardize on one format for representing a period and have all measure groups use that. I would recommend you change the SQL Query for your Actuals measure group to return values that join to the Period column in your Date table.
Understanding how this works means understanding attribute relationships and the IgnoreUnrelatedDimensions setting. If set to true then slicing by an “unrelated” attribute (one that’s below the grain or unrelated or an unrelated dimension) will just cause the measure to repeat. If set to false then it will become null.
I’m unclear why you need Time as a reference dimension. It appears to also contain a Date hierarchy. Typically Date is for days, weeks, months and years. Typically Time is for hours minutes and seconds. For processing performance reasons I would avoid reference dimensions. They are more trouble than they are worth. Add the Time dimension key to your fact tables.
The scrrenshot shows there is relation between Date and Forcast,so I do not think the root cause that is the root casue,however, you can try GreGalloway's solution, to set the property of IgnoreUnrelatedDimensions to False to test.
enter image description here

Left Join of two tables based on a range of dates

I am a newbie to SQL coding and am trying to figure out how to create a LEFT JOIN statement based on a date range. The database is analytics from a smartphone app that sends messages to users. The two tables are messageLog (which describes the messages sent to each user) and messageOpenLog (which describes the messages that are opened). Both tables are linked to the message table, but not to each other. To complicate matters, there are a couple other rules we have developed on when messages are able to be sent:
If a message is not opened within 7 days, the message can be resent on day 8.
If a message is opened, then the message can be resent within 60 days.
So, what I want to do is join the two tables together based on the following pseudocode (as I have no idea where to start with actual code):
LEFT JOIN
If (messageOpenLog.DateOpened is within 7 days of messageLog.DateSent)
and messageLog.message_id = messageOpenLog.message_id and
messageLog.user_id = messageOpenLog.user_id
Note: the date format is yyyy-mm-dd hh:mm:ss in both tables.
Any help you can provide would be greatly appreciated.
I am unable to comment on shn's answer, but there is a chance that the user has never opened the message and a messageOpenLog record has not been created. In that case you could add a messageOpenLog.message_id is null to the where clause and get those unopened messages with no corresponding messageOpenLog record as well.
I would suggest:
messagelog ml LEFT JOIN
messageOpenLog mol
ON mol.message_id = ml.message_id AND
mol.user_id = ml.user_id AND
mol.DateOpened >= ml.DateSent AND -- probably not needed
mol.DateOpened < ml.DateSent + interval '7 day'
Note that date arithmetic varies a lot among databases. The exact syntax for adding seven days may be a bit different in your database.
From what I understand from your question and the query below, you are finding all the individual messages that have a time difference of longer than 7 days between their send date and open date.
To do the time difference I would recommend using the DATEDIFF() function that is built into SQL (you may need to format the timestamps into date format with DATE()).
Since the two tables are not directly related you could do something like this:
SELECT
messageOpenLog.*,
messageLog.*
FROM
messageLog LEFT JOIN messageOpenLog ON messageLog.message_id=messageOpenLog.message_id
WHERE
messageLog.user_id = messageOpenLog.user_id AND
DATEDIFF(
day,
DATE(messageLog.timestamp),
DATE(messageOpenLog.timestamp)
) > 7
The structure of this query is dependent on the construction of your tables.
Notice I used the .timestamp column but in your tables this may be named different.
Also I'm not sure if this is actually what you want; if you want to see if the message is more than 7 days old, a different query is required.
Assuming that there is only one messageSent row, this query will get all of the messageOpen rows for the same message that are more than 7 days old.
It's very difficult to give you an exact query based on the information that was presented, such as the potential number of rows with the same message_id, as #amac mentions, there could also be cases where one of the tables has no rows with a certain message_id.

How to get count of all currently selected members of dimension

I have got a cube with date dimension:
Period
- Year
-- Quarter
--- Month
---- Date
I need to get count of all dates, selected by user (f.e. in Excel). I have tried to use calculated members like:
[Period].[Period].CurrentMember.children.count
It is good when 1 month is selected. In other ways (selected only few dates or Quarter) it returns the count of children of the next level of hierarchy.
Descendants([Period].[Period],[Period].[Period].[Date]).count
Descendants([Period].[Period].CurrentMember,[Period].[Period].[Date]).count
So I tried to use Descendants. The results are good when 1 element on any level is selected. But one you select f.e. 2 month in one Quarter - it gives counts of all elements.
How can I get count of all selected elements on Date level?
I have also tried:
[Period].[Period].[Date].count
[Period].[Period].[Date].CurrentMember.count
COUNT([Period].[Period].[Date])
COUNT([Period].[Period].[Date].CurrentMember)
To work out multiselect in Excel, you can try Dynamic Set technique. Assume your [Period] dimension has [YQMD] hierarchy, then try the following
CREATE DYNAMIC SET SelectedDates AS (
[Period].[YQMD].[Date] )
CREATE MEMBER CURRENTCUBE.[Measures].[SelectedDatasCount] AS (
SelectedDates.count
)
Refer to this SO article and MSDN discussion. Unfortunately, Mosha's article is no longer available.
Caveat - solution with Dynamic Set can hinder query performance.

wrong result of parallelperiod() for DATE in MDX

I want to extract data for same period last year and last month.
for this i am using Parallelperiod(), for eg
PARALLELPERIOD([date].[year],1,[date].[date].[20-Sep-2014]) ,
for which I am getting output : 21-Sep-2014
and
PARALLELPERIOD([date].[month],1,[date].[date].[20-Sep-2014]) ,
for which I am getting output : 16-Aug-2014
Same function would throw some other date for some other month
Can you guide about the issue, where i am doing wrong or if there is some other alternative to this?
You must have some dates that do not exist in the cube.
What the PARALLELPERIOD function is doing is saying ok we are 262 members at the [date] level into 2014 - then it goes to 2013 and finds the member at the [date] level that is also 262 members in. Therefore unless you have complete sets of dates in your cube this function will return surprising results.
Therefore the solution is to ensure that all historical dates are represented in the cube. These extra dates should not cause any extra overhead as they will be creating empty space in the cube which is dealt with very well by SSAS