How can I group my entries by TV with getResources (ModX)? - modx

I have a getResources call, the result looks more or less like this:
01.01.2016 - new year's lunch (meetings)
11.12.2015 - writing class (classes)
01.12.2015 - trip to London (trips)
23.11.2015 - french class (classes)
I can sort them by tags:
classes
meetings
trips
It works very well. This is my code:
[[!getResourcesTag?
&parents=2`
&tagKey=`Tags`
&showHidden=`1`
&tpl=`datesTpl
&limit=`3`
&includeContent=`1`
&includeTVs=`1`
&processTVs=`1`
&tvPrefix=``
&hideContainers=`1`
&pageLimit=`10`
]]
Now comes the part, that makes problems to me. I want to group the result by month. So the result I would like to achieve is:
January 2016
01.01.2016 - new year's lunch (meetings)
December 2015
11.12.2015 - writing class (classes)
01.12.2015 - trip to London (trips)
November 2015
23.11.2015 - french class (classes)
The TV, that outputs the date has the name "date". This TV gives me for every entry a timestamp output. For example: "2015-12-11 00:56:00".
I wrote a snippet (formatDate), that outputs me later the format I wish. I use it like this:
[[formatDate? &date=`[[+date]]`]]
So I thought I could use Archivist Grouper for that issue. But it is not working. Somehow it doesn't process my TVs. Here is my code:
1
[[!ArchivistGrouper? &parents=`2` &itemTpl=`datesTpl` &includeTVs=`1` &tvPrefix=`` &includeContent=`1` &processTVs=`1`]]
My result with Archivist Grouper is:
January 2016
01.01.2016 - new year's lunch ()
December 2015
01.01.2016 - writing class ()
01.01.2016 - trip to London ()
November 2015
01.01.2016 - french class ()
So my question is, can I get the result I wish also with getResources? Or do you have any idea to get it run! I hope very much you can help. I am happy for every hint smiley

you will not be able to set up getResources to output anything in a grouped format. You will have to write your own snippet.
You can turn on debugging in getResources to see what sort of query it is outputting and either copy that to your snippet [not so great] or rebuild it using xPDO [better], iterate through that to get your grouping and you would have to bone up on getChunk to format your output.

This will break it up by year.
[[pdoNeighbors?
&id=`[[+id]]`
&tplWrapper=`#INLINE [[+next]]`
&sortby=`publishedon`
&sortdir=`asc`
&tplNext=`#INLINE [[+publishedon:strtotime:date=`%Y`]]`
&toPlaceholder=`neighborYear`
]]
[[+neighborYear:notequalto=`[[+year]]`:then=`<h3>[[+neighborYear]]</h3>`]]
<dt>[[+publishedon:strtotime:date=`%m/%d/%Y`]]</dt>
<dd>[[+pagetitle]]</dd>
[[+publishedon:strtotime:date=`%Y`:toPlaceholder=`year`]]
To break it down further by year and month use %Y%m

Related

Create Date from MM/DD format and include current year? Power Query

I have a table that has a series of Columns with data I need to split out. Example below
STATUS#10/16 12:00:00 (CODE)
I've been able to split it easy enough and when I originally tried to set the date on an older dataset it identified it as a date e.g. 16th Oct 2021 However I started to get errors on this date column and trying with different datasets (10/12, 10/13, 10/14) it is not finding the date. I tried the following query code but I'm receiving errors
[STATUS DATE] is split to 10/14, 10/15 etc
#date( Date.Year(DateTime.LocalNow), Date.Month(Text.End([STATUS DATE]), 2), Date.Day(Text.Start([STATUS DATE]),2))
However I'm getting a function error so I tried
Date.From(Date.Day(Text.Start([STATUS DATE]),2) & Date.Month(Text.End([STATUS DATE]),2) & Date.Year(DateTime.LocalNow)
I have also tried to do this from an example column however the query created is looking at the cell value e.g. if 10/14 then 14/10/2021 else if 13/10 then 14/10/2021. This method i feel is prone for error once I include a larger dataset.
Is there anyway I can determine the date value based on mm/dd format? But with year end in mind, make the YYYY be determined by current year unless we move into Jan and then I don't want the Oct, Nov, Dec value showing as 2022.
You don't really show what your original data looks like.
But if it is like:
Source
Then you can use this code in the Add Custom Column dialog:
let
split=Text.SplitAny([STATUS DATE],"#/ "),
mnth = Number.From(split{1}),
dy = Number.From(split{2})
in
#date(Date.Year(DateTime.LocalNow()),mnth,dy)
The Text.SplitAny function lets you input a list of delimiters and the text will split on all of them. So it is relatively simple to extract the month and day values
to create:
Split [STATUS DATE] one more time into [Month] and [Day] column, using the "/" as a separator. Then you don't have to bother with 1 or 2 digit numbers and you can simply use this formula:
#date(Date.Year(DateTime.LocalNow()), [Month], [Day])
DateTime.LocalNow() is a function, so you need to add the brackets.
[Month] and [Day] are numbers already, so you don't need the Date.Month() or Date.Day() functions.

Excel Using concatenate to compare dates

I have a table containing several columns of which one is a date/time field. I am trying to get a count of instances per day using the following
=COUNTIFS(Table4[Data],"Apple",Table4[Date],(CONCATENATE(V4,"*")))
Data Date Comp Date Count
Apple 6/12/18 1:00 PM 6/12/18 12:00 AM 0
Apple 6/12/18 7:00 AM
Orange 6/12/18 1:30 PM
Apple 6/11/18 11:23 AM
From my understanding of all the moving parts here I should be checking to see if "Apple" exists in the data column and then if "6/12/18" with any amount or type of characters after it exists. If both are true I will then get a count + 1 leaving me with a value of 2 in the above example.
What I actually get however is a 0 unless I match the time portion of date the data to be exactly the same and then removed the wildcard ,"*" from the equation.
Am I doing something wrong or can the wildcard not be used to accomplish what I am trying?
Thanks!
I think you should set your criteria properly.
If you add an additional column next to your Date that contains calculates the integer value of your date using INT() and format the display as DATE (m/d/yyyy) you should then be able to use the following COUNTIFS formula
=COUNTIFS(Table4[Data], "Apple", Table4[Date], "=6/12/18")
See the explanatory video from their Office' support site: https://support.office.com/en-us/article/countifs-function-dda3dc6e-f74e-4aee-88bc-aa8c2a866842
If your [Date] column is a datetime or smalldatetime, you can work with it using CONVERT function, depending on how you want to group.
For example, if you don't care about the time to do the group, you could use the next query:
SELECT CONVERT(varchar,[Date],103), [Data], COUNT(*)
FROM [test_delete].[dbo].[Table1]
GROUP BY CONVERT(varchar,[Date],103), [Data]
This should result in something like this:
[Date] [Data] [Count]
11/06/2018 Apple 1
12/06/2018 Apple 2
12/06/2018 Orange 1
Hope this helps you
If your dates are stored as dates instead of text, use the following:
=COUNTIFS(Table4[Data],"Apple",Table4[Date],">="&V4,Table4[Date],"<"&V4+1)

How can I convert date to a readable form in Angular and also concatenate two dates?

For any event, Im getting dates in my html file in the following manner:
Start Date: 2017-09-25T10:00:00
End Date: 2017-09-25T11:00:00
In my Controller I have them saved as :
Event= {StartDate: start, EndDate: end}
I am looking for a way to output them in my html with some concatenation and trimming done to the date. My event date will always be the same so I would like to be displayed something like:
September 09 2017, 10 AM - 11:00 AM
Help Needed!
Here's a working plunker that will give you a feel for the date formatting you're after: https://plnkr.co/edit/tmxQY9RyqGzHwCKhvQN0?p=preview
The template interpolation is key here
{{Event.StartDate | date:"MMMM dd yyyy ', ' h"}} {{Event.EndDate | date: "'-' h:mm a"}}
Note: you could save yourself from parsing the left side of the "-" with Angular's 'longDate', but that will add a comma after the day of the month (e.g. September 20, 2017 vs September 20 2017).
Check out the docs for detailed info on which date parsing character does what.
Just use JavaScript, you have the split function (ex: .split(/[-T]+/)). For the month you have the 09 number, create your own function to get the month by array's indexes.

modx getResources tv

I have a page for a sports club based on ModXCMS 2.1.4.
For a list of sport classes I have appr. 30 Documents for the different.
Each of this has template variables like abteilung, Wochentag, Startzeit, etc.
The tv.Wochentag contains Montag,Dienstag,Mittwoch,Donnerstag,Freitag,Samstag,Sonntag as weekdays.
Now my problem:
The output is not sorted by the variable.
Here my code:
[[getResources?
&parents=`19`
&debug=`1`
&tvFilters=`abteilung==[[*abteilung]]`
&sortby=`{tv.Wochentag:"Montag,Dienstag,Mittwoch,Donnerstag,Freitag,Samstag,Sonntag":"ASC",tv.UhrzeitStart:"ASC"}`
&tpl=`snipSportangebot`
&includeTVs=`1`
&tvPrefix=``
&limit=`0`
&processTVs=`1`]]
Finaly I would like to sort by Wochentag (Weekday) and StartZeit (Starttime/Time).
What have I done wrong?
Has anyone any hint on this.
Thanks in advance
Christian
Join weekday and starttime to one TV - Input Type: Date, then you will be able to sorting by TV in getResources:
sortbyTV - Template Variable to sort by
sortdirTV - Order which to sort by when using sortbyTV
sortbyTVType - Specify the data type of the sortby TV. Possible values are string, integer, decimal, datetime
https://rtfm.modx.com/extras/revo/getresources
Youy cannot sort by a TV using sortby [see the docs] if you try to use sortbyTV & sortdirTV it's going to sort them alphabetically for you.
set your day of the week tvs values to numeric :
Montag==0||Dienstag==1||Mittwoch==2||Donnerstag... etc
then your sortbyTV & sortdirTV should behave as expected

How to use the CUBEMEMBERPROPERTY function

In cell A1 we have this:
=CUBEMEMBER("OurCube","TAIL([Date].[Date - Calendar Month].[Calendar Day].MEMBERS,1).item(0)","TargetMember")
It works fine and returns a single member that is yesterday.
In A2 we have a formula that is attempting to return the actual date - so I thought the CUBEMEMBERPROPERTY function would work:
=CUBEMEMBERPROPERTY("OurCube",A1,"member_caption")
The above returns #N/A
I don't know what CUBEMEMBERPRPERTY does but apparently it doesn't mean what you think it means!
If you need to get a certain property of a field according to another field, this is the way to do it:
Let's say, I wanted the Financial Year's month name (FY Month Name) based on a certain date key (I live in Australia, the financial year finishes at June):
=CUBEMEMBER("ThisWorkbookDataModel", "EXISTS([Dim Period].[FY Month Name].Children, [Dim Period].[Datekey].[20160731])")
And if the value of "20160731" has been in a certain cell, it would go like this:
=CUBEMEMBER("ThisWorkbookDataModel", "EXISTS([Dim Period].[FY Month Name].Children, [Dim Period].[Datekey].["&A8&"])")
Both would give me the correct answer: 01 - July
And I would like to thank the following posts for their help:
https://wessexbi.wordpress.com/2014/02/16/a-cubememberproperty-equivalent-with-powerpivot/
http://www.mrexcel.com/forum/power-bi/730287-function-cubememberproperty-always-return-n.html

Resources