I am running some query's against our incident logging database for our individual customers. What I want to return is all the month names from 2012 and a count of how many open incidents there have been. This works fine for a customer who has been with us for over 12 months but not for a customer who has been with us for a shorter period of time.
The query I have is this:
SELECT DATE_FORMAT(FROM_UNIXTIME(createdtime/1000), '%Y') as 'Year',
DATE_FORMAT(FROM_UNIXTIME(createdtime/1000), '%M') as 'Month',
count(wo.workorderid) as 'Total Logged'
FROM workorder_threaded wot
inner join workorder wo
on wo.workorderid = wot.workorderid
and wo.siteid = 4806
and DATE_FORMAT(FROM_UNIXTIME(createdtime/1000), '%Y') <> '2011'
where wot.workorderid = wot.thd_woid
GROUP BY DATE_FORMAT(FROM_UNIXTIME(createdtime/1000), '%Y%m')
The output I get is this:
Year Month Total Logged
2012 August 3
2012 September 356
2012 October 212
2012 November 120
I need however the following:
Year Month Total Logged
2012 January 0
2012 February 0
2012 March 0
2012 April 0
2012 May 0
2012 June 0
2012 July 0
2012 August 3
2012 September 356
2012 October 212
2012 November 120
2012 December 0
It doesn't have to be limited by year i.e. the call logging DB has data in this from 2011 so the query can be modified to filter the year range.
I know that this is not populating because the data does not exist and I have seen ways of creating a numbers \ date table and referencing this to populate the date but am struggling to do this. I have also changed around joins and where conditions to no avail.
Thanks in advance.
You need to use LEFT JOIN here
Related
I have a column with a year and a ISO week. I would like to get the corresponding date, but at the moment my formula is wrong.
I have the following table:
Year Week
2020 52
2020 53
2021 1
2021 2
I used in power query editor the following formula:
Date.StartOfWeek(Date.AddWeeks(#date([Year], 1, 1), [Week]), Day.Monday)
and I obtained:
Year Week Date
2020 52 28.12.2020
2020 53 04.01.2021
2021 1 04.01.2021
2021 2 11.01.2021
What I would like to have instead:
Year Week Date
2020 52 21.12.2020
2020 53 28.12.2020
2020 1 04.01.2021
2021 2 11.01.2021
For example, in DAX, this works:
Date = DATE([Year],1,-2)-WEEKDAY(DATE([Year],1,3))+[Week]*7
But I would prefer to have it in power query because my data source needs to be updated regularly. Thank you for your attention!
In case you have the same problem, this works now:
Date.AddDays((Date.AddDays(#date([Year],1,1),-4)),(-Date.DayOfWeek(Date.AddDays(#date([Year],1,1),-4)) + [Week]*7))
I need to create a field of previous year total sales in the current year column.
Here is an example based on it being 2018 today: in 2018, it should be 2017 total sales(full year), in 2019, it should be 2018 Sales(jan-apr would be only months in may), and 2020 should be blank, as there are no data in 2019 yet, etc.
Use the calculation to make it as "Date-1".
I am trying to plot on a line chart running data for 3 fiscal years. My fiscal year being 30 June and not 31 December
Data for Year 1 [1 July 2015 to 30 June 2016]
Data for Year 2 [1 July 2016 to 30 June 2017]
Data for Year 3 [1 July 2016 to 30 June 2018] This is the current year
The following is what I am hoping to achieve.
3 Year Chart
I am not certain how to achieve this.
I was thinking the following might be of some relevance
Revenue from Start = CALCULATE(Report[Revenue], DATESBETWEEN('Dates'[Date], BLANK(), LASTDATE('Dates'[Date])))
I have had it suggested to set up a new measure "Date2". But I really am not sure how to do this. Also given that I am after a third series would I then need to set up a "Date3"
For Date2 [and Date3 if applicable], how would this/these measures be coded, ie is this logical
Date2 = DATE(2015,07,01)
Date3 = DATE(2016,07,01)
Thanks for any help that can be offered. You will see from my question, I know what I want as an output, but have no idea how to really implement.
I would use the TOTALYTD function, e.g.
Revenue from Start = TOTALYTD ( [Revenue] , 'Dates'[Date] , "30 June 2018" )
This blog post is probably the best description of this and related functions:
https://www.sqlbi.com/articles/time-intelligence-in-power-bi-desktop/
I am trying to truncate several dates of a certain month to the start of the week, except the ones that start in the previous month.
Example:
Wednesday 5 Dec 2012 should be truncated to Monday 3 Dec 2012
Saturday 1 Dec 2012 should not be truncated to Monday 26 Nov 2012
For truncating the dates I am using:
date_trunc('week', dates.d)
The problem is that Saturday 1 Dec 2012 still gets truncated to Monday 26 Nov 2012
Can I add a constraint to it, so that it takes the month into account?
Thanks in advance :)
NOTE: I am using version 9.2
GREATEST(date_trunc('week', dates.d), date_trunc('month', dates.d))
I'm trying to take one group and put it in two different columns. I know you can do that for the details of a group in the section expert but it won't allow you do so for a group. The group is date that I've separated by months for the all of last year and this year to the current date and I want last year's months in one column and this year's months in another column. Like this:
January 2011 January 2012
February 2011 February 2012
March 2011 March 2012
April 2011 April 2012
May 2011
June 2011
July 2011
August 2011
September 2011
October 2011
November 2011
December 2011
That way the months are easy to compare and they can be drilled down. Any ideas?
In Details section's 'Section Expert', select 'Format with Multiple Columns'
Select the (now visible) Layout tab
Select 'Format Groups with multiple column'
Add a second group on your date field by year (make sure it is 'outside' the mm/yyyy grouping)
Size the footer of the section you created in #4 to get each year to be in its own column
If you group by month name (like monthname({transaction.date}) so January 2011 and 2012 will be in the same group) then you can use a running total to summarize the years individually within that group. You can do this by creating two running total fields, one with an evaluate formula like year({transaction.date})=2010 and another with the formula year({transaction.date})=2011.
Note that running totals won't work in the group header though, so you'd need to migrate those fields down into the group footer instead.
How about using a cross-tab like:
2011 2012
January 10 12
February 5 12
March 8 1
This would be a lot more flexible.