Defining time dimension in Mondrain Schema? - postgresql

I am trying to define time dimension in Mondrian schema. In Mondrian time dimension it require 3 level-type must be Years, Quarters, Months.
But my table contain only one date field. So how it is possible?
Can I use postgreSQL query in Mondrian? So I can use 3 query to select Years, Quarters and Month from single date field.

Create simple table with only one date column:
create table tmp_cube as (select generate_series('2011-01-01'::date, '2012-01-01'::date, '1 day')::date gs);
Create dummy cube:
<Schema name="New Schema1">
<Cube name="Test" visible="true" cache="true" enabled="true">
<Table name="tmp_cube" schema="public" alias="">
</Table>
<Dimension type="TimeDimension" visible="true" foreignKey="gs" name="Time Dimension">
<Hierarchy name="New Hierarchy 0" visible="true" hasAll="true" primaryKey="gs">
<View alias="test_view">
<SQL dialect="generic">SELECT gs, extract(year from gs) as year, extract(quarter from gs) as quarter, extract(month from gs) as month FROM tmp_cube</SQL>
</View>
<Level name="Year" visible="true" column="year" type="Integer" internalType="int" uniqueMembers="false" levelType="TimeYears">
</Level>
<Level name="Quarter" visible="true" column="quarter" type="Integer" uniqueMembers="false" levelType="TimeQuarters">
</Level>
<Level name="Month" visible="true" column="month" type="Integer" uniqueMembers="false" levelType="TimeMonths">
</Level>
</Hierarchy>
</Dimension>
<Measure name="Count Rows" column="gs" aggregator="count" visible="true">
</Measure>
</Cube>
</Schema>
Now I see in Saiku:

Related

Update the counter by +1 when another record with two similar values exists in xslt 2.0

I have the below xml:
<EmployeeLeaveDataUpsertRequest>
<Row>
<Emp_id>11</Emp_id>
<Pay_slip_no>1</Pay_slip_no>
<Pay_comp>AU_0299</Pay_comp>
<Hours>136</Hours>
<Date_from_ec>20170401</Date_from_ec>
<Date_to_ec>20170429</Date_to_ec>
<Date_ped> </Date_ped>
<No_of_period>1</No_of_period>
<Ma_ind>M</Ma_ind>
<Fa_ind>N</Fa_ind>
<Counter>1</Counter>
</Row>
<Row>
<Emp_id>12</Emp_id>
<Pay_slip_no>1</Pay_slip_no>
<Pay_comp>AU_0900</Pay_comp>
<Hours>40</Hours>
<Date_from_ec>20170206</Date_from_ec>
<Date_to_ec>20170210</Date_to_ec>
<Date_ped> </Date_ped>
<No_of_period>1</No_of_period>
<Ma_ind>M</Ma_ind>
<Fa_ind>N</Fa_ind>
<Counter>1</Counter>
</Row>
<Row>
<Emp_id>11</Emp_id>
<Pay_slip_no>1</Pay_slip_no>
<Pay_comp>AU_0299</Pay_comp>
<Hours>8</Hours>
<Date_from_ec>20170111</Date_from_ec>
<Date_to_ec>20170115</Date_to_ec>
<Date_ped> </Date_ped>
<No_of_period>1</No_of_period>
<Ma_ind>M</Ma_ind>
<Fa_ind>N</Fa_ind>
<Counter>1</Counter>
</Row>
In the above xml you can see that every record has an element counter with default value set as 1.
In an event for same Emp_id and Pay_comp then I need to set the counter as 1 for first record , 2 for second record and so on.
Like in the above xml you can see two records where the Emp_id is 11 and Pay_comp is AU_0299 -- so for the first one set the counter as 1 and for the next one a 2.
output xml:
<EmployeeLeaveDataUpsertRequest>
<Row>
<Emp_id>11</Emp_id>
<Pay_slip_no>1</Pay_slip_no>
<Pay_comp>AU_0299</Pay_comp>
<Hours>136</Hours>
<Date_from_ec>20170401</Date_from_ec>
<Date_to_ec>20170429</Date_to_ec>
<Date_ped> </Date_ped>
<No_of_period>1</No_of_period>
<Ma_ind>M</Ma_ind>
<Fa_ind>N</Fa_ind>
<Counter>1</Counter>
</Row>
<Row>
<Emp_id>11</Emp_id>
<Pay_slip_no>1</Pay_slip_no>
<Pay_comp>AU_0299</Pay_comp>
<Hours>8</Hours>
<Date_from_ec>20170111</Date_from_ec>
<Date_to_ec>20170115</Date_to_ec>
<Date_ped> </Date_ped>
<No_of_period>1</No_of_period>
<Ma_ind>M</Ma_ind>
<Fa_ind>N</Fa_ind>
<Counter>2</Counter>
</Row>
<Row>
<Emp_id>12</Emp_id>
<Pay_slip_no>1</Pay_slip_no>
<Pay_comp>AU_0900</Pay_comp>
<Hours>40</Hours>
<Date_from_ec>20170206</Date_from_ec>
<Date_to_ec>20170210</Date_to_ec>
<Date_ped> </Date_ped>
<No_of_period>1</No_of_period>
<Ma_ind>M</Ma_ind>
<Fa_ind>N</Fa_ind>
<Counter>1</Counter>
</Row>
I have tried for loop but couldn't succeed. Need your inputs on the XSLT code which could achieve it
You could use a key to identify duplicates, with XSLT 3.0 (as now supported by Saxon 9.8 or current versions of Altova XMLSpy and Raptor) it is as easy as:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:math="http://www.w3.org/2005/xpath-functions/math"
exclude-result-prefixes="xs math"
expand-text="yes"
version="3.0">
<xsl:key name="group" match="Row" use="Emp_id , Pay_comp" composite="yes"/>
<xsl:mode on-no-match="shallow-copy"/>
<xsl:template match="Row[not(. is key('group', (Emp_id , Pay_comp))[1])]/Counter">
<xsl:copy>{index-of(key('group', (../Emp_id , ../Pay_comp)), ..)}</xsl:copy>
</xsl:template>
</xsl:stylesheet>
With XSLT 2.0 you can translate the above to
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:math="http://www.w3.org/2005/xpath-functions/math"
exclude-result-prefixes="xs math"
version="2.0">
<xsl:key name="group" match="Row" use="concat(Emp_id, '|', Pay_comp)"/>
<xsl:template match="#* | node()">
<xsl:copy>
<xsl:apply-templates select="#* | node()"/>
</xsl:copy>
</xsl:template>
<xsl:template match="Row[not(. is key('group', concat(Emp_id, '|', Pay_comp))[1])]/Counter">
<xsl:copy>
<xsl:value-of select="index-of(key('group', concat(../Emp_id, '|', ../Pay_comp)), ..)"/>
</xsl:copy>
</xsl:template>

How to print two phone numbers with spaces in the same row using jasper reports? [duplicate]

This question already has answers here:
formatting a string to a currency format in jasper report
(8 answers)
Closed 7 years ago.
I need to print two numbers in the same row with spaces or commas as
442233378,556664446 in this way I need to print using jasper reports.I am using the variable as $F(alias_name) to print these numbers.But it is printing out of the page as shown in the image it has to print the number above the line where the first number is printed.Please help me.
I think you get get a solution for this by just changing your query.
I have added a GROUP_CONCAT function onto your alias_name field, you can read more on what this does here.
SELECT
GROUP_CONCAT(DISTINCT alias_name SEPARATOR ', ') AS alias_name
FROM
service_alias
WHERE
service_id IN
(
SELECT
id
FROM
service
WHERE
order_id IN
(
SELECT
id
FROM
purchase_order
WHERE
id IN
(
SELECT
order_id
FROM
order_process
WHERE
invoice_id = $P{invoiceId}
)
AND
period_id != 1
)
)
Here is the query added into the entityDetails.jrxml file:
<?xml version="1.0" encoding="UTF-8"?>
<jasperReport xmlns="http://jasperreports.sourceforge.net/jasperreports" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://jasperreports.sourceforge.net/jasperreports http://jasperreports.sourceforge.net/xsd/jasperreport.xsd" name="Entity details" pageWidth="595" pageHeight="875" whenNoDataType="AllSectionsNoDetail" columnWidth="595" leftMargin="0" rightMargin="0" topMargin="0" bottomMargin="0" >
<property name="com.jasperassistant.designer.GridHeight" value="12"/>
<property name="com.jasperassistant.designer.GridWidth" value="12"/>
<property name="com.jasperassistant.designer.SnapToGrid" value="false"/>
<property name="com.jasperassistant.designer.Grid" value="false"/>
<property name="ireport.zoom" value="1.0"/>
<property name="ireport.x" value="0"/>
<property name="ireport.y" value="0"/>
<parameter name="invoiceId" class="java.lang.Integer"/>
<queryString>
<![CDATA[
SELECT
GROUP_CONCAT(DISTINCT alias_name SEPARATOR ', ') AS alias_name
FROM
service_alias
WHERE
service_id IN
(
SELECT
id
FROM
service
WHERE
order_id IN
(
SELECT
id
FROM
purchase_order
WHERE
id IN
(
SELECT
order_id
FROM
order_process
WHERE
invoice_id = $P{invoiceId}
)
AND
period_id!=1
)
)
]]>
</queryString>
<field name="alias_name" class="java.lang.String"/>
<title>
<band splitType="Stretch"/>
</title>
<detail>
<band height="62">
<textField isBlankWhenNull="true">
<reportElement x="50" y="5" width="197" height="15" />
<textElement>
<font size="10" isBold="true"/>
</textElement>
<textFieldExpression class="java.lang.String"><![CDATA[$F{alias_name}]]></textFieldExpression>
</textField>
<image>
<reportElement x="18" y="4" width="18" height="13" />
<imageExpression><![CDATA["/opt/apps/openbrm-2.0/openbrm/resources/logos/phone-symbol.png"]]></imageExpression>
</image>
</band>
</detail>
</jasperReport>

CRM 2011 Chart: count of grouped dates for other field

I have an entity expressing employee absences split per half day (AM and PM). the entity has 4 relevant fields: the employee name (another custom entity), a reason for absence (holiday, overtime reimbursement, paid vacation, allowed leave,... 11 in total), the date of absence and whether it's an AM or PM absence (dropdown using 2 values). If an employee is absent the entire day, 2 records are made, 1 for AM and 1 for PM.
I now have to make a graph which shows the following:
Group all absences per employee (5 absent employees is 5 groups);
group all absences for a specific employee per reason for absence (an employee with 2 different absences gets 2 adjacent columns in his group);
The data shown is a count of all the absences, grouped by date (2 absences, 1 AM and 1 PM, on the same date should count as 1 absence, not 2). In effect, I need a count of unique dates.
I have managed to make a basic graph which has the employee and absence reason groups completed. However, I cannot figure out how to count unique dates.
What i've got so far is:
<visualization>
<visualizationid>{CA31385D-FE63-E311-A895-005056A03018}</visualizationid>
<name>Datum afwezigheid bij personeelsfiche en reden van afwezigheid</name>
<primaryentitytypecode>acm_tijdindeling</primaryentitytypecode>
<datadescription>
<datadefinition>
<fetchcollection>
<fetch mapping="logical" aggregate="true">
<entity name="acm_tijdindeling">
<attribute groupby="true" alias="group_personeelsfiche" name="acm_personeelsfiche" />
<attribute alias="count_datumafwezigheid" name="acm_datumafwezigheid" aggregate="count" />
<attribute groupby="true" alias="group_redenvanafwezigheid" name="acm_redenvanafwezigheid" />
</entity>
</fetch>
</fetchcollection>
<categorycollection>
<category alias="group_personeelsfiche">
<measurecollection>
<measure alias="count_datumafwezigheid" />
</measurecollection>
</category>
</categorycollection>
</datadefinition>
</datadescription>
<presentationdescription>
<Chart Palette="None" PaletteCustomColors="55,118,193; 197,56,52; 149,189,66; 117,82,160; 49,171,204; 255,136,35; 97,142,206; 209,98,96; 168,203,104; 142,116,178; 93,186,215; 255,155,83">
<Series>
<Series ChartType="Column" IsValueShownAsLabel="True" Font="{0}, 9.5px" LabelForeColor="59, 59, 59" CustomProperties="PointWidth=0.75, MaxPixelPointWidth=40"></Series>
</Series>
<ChartAreas>
<ChartArea BorderColor="White" BorderDashStyle="Solid">
<AxisY LabelAutoFitMinFontSize="8" TitleForeColor="59, 59, 59" TitleFont="{0}, 10.5px" LineColor="165, 172, 181" IntervalAutoMode="VariableCount">
<MajorGrid LineColor="239, 242, 246" />
<MajorTickMark LineColor="165, 172, 181" />
<LabelStyle Font="{0}, 10.5px" ForeColor="59, 59, 59" />
</AxisY>
<AxisX LabelAutoFitMinFontSize="8" TitleForeColor="59, 59, 59" TitleFont="{0}, 10.5px" LineColor="165, 172, 181" IntervalAutoMode="VariableCount">
<MajorTickMark LineColor="165, 172, 181" />
<MajorGrid LineColor="Transparent" />
<LabelStyle Font="{0}, 10.5px" ForeColor="59, 59, 59" />
</AxisX>
</ChartArea>
</ChartAreas>
<Titles>
<Title Alignment="TopLeft" DockingOffset="-3" Font="{0}, 13px" ForeColor="59, 59, 59"></Title>
</Titles>
<Legends>
<Legend Alignment="Center" LegendStyle="Table" Docking="right" IsEquallySpacedItems="True" Font="{0}, 11px" ShadowColor="0, 0, 0, 0" ForeColor="59, 59, 59" />
</Legends>
</Chart>
</presentationdescription>
<isdefault>false</isdefault>
</visualization>
I've tried adding groupby="true" dategrouping="day" to the count_datumafwezigheid aggregate, but then I get an "invalid XML" error.
Here's a link on how to count unique items http://crmchartguy.wordpress.com/2013/12/12/count-distinct-or-unique-items-in-ms-crm-charts/
I had a similar problem once - im not sure its possible to aggregate DateTime - See Thread:
Fetch DateTime CRM 2011

Just one pie in report chart if parameter values are equal

Was created pie 3d chart. It has several params. For example, one of them call "errors" and another - "success". Both is Integer. If values are different, for example 10 and 9, all work fine, but if values are equal, it draw like one pie, and in label expression writed only one value.
In this image I set 10 errors and 10 success, but as can be seen, JasperReports draw just 10 success.
I check it in iReport and by generation report in Java, but results was same.
One more example.
<parameter name="access" class="java.lang.Number"/> set 10
<parameter name="configChange" class="java.lang.Number"/> set 10
<parameter name="creating" class="java.lang.Number"/> set 5
<parameter name="deleting" class="java.lang.Number"/> set 10
<parameter name="updating" class="java.lang.Number"/> set 5
<parameter name="objRequest" class="java.lang.Number"/> set 7
<parameter name="unknown" class="java.lang.Number"/> set 8
Result:
jrxml-file:
<pie3DChart>
<chart isShowLegend="true" renderType="draw" theme="default">
<reportElement uuid="1ea2fe12-8478-48a3-8a16-828cb17bc242" positionType="FixRelativeToBottom" mode="Opaque" x="0" y="50" width="430" height="280" backcolor="#CCFFFF"/>
<chartTitle/>
<chartSubtitle/>
<chartLegend/>
</chart>
<pieDataset>
<pieSeries>
<keyExpression><![CDATA[$P{errors}]]></keyExpression>
<valueExpression><![CDATA[$P{errors}]]></valueExpression>
<labelExpression><![CDATA["Error"]]></labelExpression>
</pieSeries>
<pieSeries>
<keyExpression><![CDATA[$P{success}]]></keyExpression>
<valueExpression><![CDATA[$P{success}]]></valueExpression>
<labelExpression><![CDATA["Success"]]></labelExpression>
</pieSeries>
</pieDataset>
<pie3DPlot depthFactor="0.2">
<plot backgroundAlpha="0.1" foregroundAlpha="0.6">
<seriesColor seriesOrder="0" color="#FF0000"/>
<seriesColor seriesOrder="1" color="#0066FF"/>
</plot>
<itemLabel/>
</pie3DPlot>
</pie3DChart>

XSL Transform extracting min and max dates

I'm trying to extract min and max dates from an XML source. I'm getting a nodeset into my variables and I need the actual date value within the nodes and can't find how to get it.
Source XML:
<Info dataSource="source">
<Detail>
<StartDate>20121211</StartDate>
<EndDate>20130112</EndDate>
</Detail>
<Detail>
<StartDate>20121211</StartDate>
<EndDate>20130112</EndDate>
</Detail>
<Detail>
<StartDate>20121211</StartDate>
<EndDate>20130112</EndDate>
</Detail>
<Detail>
<StartDate>20121218</StartDate>
<EndDate>20130114</EndDate>
</Detail>
</Info>
The XSL code:
<xsl:if test="//StartDate != '' and //EndDate != ''">
<xsl:variable name ="startDate">
<xsl:for-each select="//StartDate">
<xsl:sort select="StartDate" data-type="text" order="ascending"/>
<xsl:if test="position() = 1">
<xsl:value-of select="." />
</xsl:if>
</xsl:for-each>
</xsl:variable>
<xsl:variable name ="endDate">
<xsl:for-each select="//EndDate">
<xsl:sort select="EndDate" data-type="text" order="descending"/>
<xsl:if test="position() = 1">
<xsl:value-of select="." />
</xsl:if>
</xsl:for-each>
</xsl:variable>
</xsl:if>
The dates are formatted correctly to support the sorts and retrieval, the issue is once the variables are populated I can't find how to access their values:
If you're using XSLT 2.0 you have min and max functions which do the work for you. XSLT 1.0 doesn't have these functions, but you can cheat by doing this (may be rather inefficient for large inputs, but it works):
<xsl:variable name="startDate" select="string(//StartDate[not(. > //StartDate)])" />
and similarly for the endDate. The trick here is that you're looking for the StartDate d for which there is no other StartDate that d is greater than.