I'm trying to get running/cumulative average of a distinct count of a field over a time period set by slicers. Since finding this specific solution has been difficult, I've been working toward just getting a running/cumulative total of the distinct count but every solution I've tried there has not been working.
Solutions that I've tried without success:
https://www.daxpatterns.com/cumulative-total/#
Unique Orders RT =
VAR LastVisibleDate =
MAX ( iDashUndAndComProcedure[Settlement Date] )
VAR FirstVisibleDate =
MIN ( iDashUndAndComProcedure[Settlement Date] )
VAR LastDateWithOrders =
CALCULATE (
MAX ( iDashUndAndComProcedure[Settlement Date] ),
REMOVEFILTERS () -- Use ALL ( Sales ) if REMOVEFILTERS () and ALL ()
-- are not available
)
VAR Result =
IF (
FirstVisibleDate <= LastDateWithOrders,
CALCULATE (
iDashUndAndComProcedure[Unique Order Count],
iDashUndAndComProcedure[Settlement Date] <= LastVisibleDate
)
)
RETURN
Result
This creates a total row without a date but the running total isn't a running total, it's the same distinct count.
The Running-Total quick measure in Power BI just returns the distinct count.
Unique Order Count running total in Settlement Date =
CALCULATE(
[Unique Order Count],
FILTER(
ALLSELECTED('iDashUndAndComProcedure'[Settlement Date]),
ISONORAFTER('iDashUndAndComProcedure'[Settlement Date], MAX('iDashUndAndComProcedure'[Settlement Date]), DESC)
)
)
I tried the following as well but it returns between 40-41 at every data point:
Average Clearance Officer Assignments Unique Cumulative =
CALCULATE( [Average Assignments for Unique Orders per Clearance Officer], FILTER( ALLSELECTED( iDashUndAndComProcedure ), iDashUndAndComProcedure[Order Number Only] < max( iDashUndAndComProcedure[Order Number Only] )))
See below for the data being utilized in the chart.
<table class="tg">
<thead>
<tr>
<th class="tg-0lax">Year</th>
<th class="tg-0lax">Month</th>
<th class="tg-0lax">Orders (including A,B,C,etc. Portfolio files)</th>
<th class="tg-0lax">Unique Orders</th>
<th class="tg-0lax">Average Assignments per Clearance Officer</th>
<th class="tg-0lax">Average Assignments for Unique Orders per Clearance Officer</th>
<th class="tg-0lax">Count of Clearance Officer</th>
</tr>
</thead>
<tbody>
<tr>
<td class="tg-0lax">2019</td>
<td class="tg-0lax">September</td>
<td class="tg-0lax">122</td>
<td class="tg-0lax">107</td>
<td class="tg-0lax">6.777777777777797</td>
<td class="tg-0lax">5.944444444444454</td>
<td class="tg-0lax">18</td>
</tr>
<tr>
<td class="tg-0lax">2019</td>
<td class="tg-0lax">October</td>
<td class="tg-0lax">210</td>
<td class="tg-0lax">107</td>
<td class="tg-0lax">11.666666666666659</td>
<td class="tg-0lax">5.94444444444443</td>
<td class="tg-0lax">18</td>
</tr>
<tr>
<td class="tg-0lax">2019</td>
<td class="tg-0lax">November</td>
<td class="tg-0lax">198</td>
<td class="tg-0lax">117</td>
<td class="tg-0lax">11</td>
<td class="tg-0lax">6.5</td>
<td class="tg-0lax">18</td>
</tr>
<tr>
<td class="tg-0lax">2019</td>
<td class="tg-0lax">December</td>
<td class="tg-0lax">262</td>
<td class="tg-0lax">183</td>
<td class="tg-0lax">13.099999999999941</td>
<td class="tg-0lax">9.150000000000048</td>
<td class="tg-0lax">20</td>
</tr>
<tr>
<td class="tg-0lax">2020</td>
<td class="tg-0lax">January</td>
<td class="tg-0lax">147</td>
<td class="tg-0lax">130</td>
<td class="tg-0lax">4.899999999999987</td>
<td class="tg-0lax">4.333333333333336</td>
<td class="tg-0lax">30</td>
</tr>
<tr>
<td class="tg-0lax">2020</td>
<td class="tg-0lax">February</td>
<td class="tg-0lax">176</td>
<td class="tg-0lax">122</td>
<td class="tg-0lax">8</td>
<td class="tg-0lax">5.545454545454527</td>
<td class="tg-0lax">22</td>
</tr>
<tr>
<td class="tg-0lax">2020</td>
<td class="tg-0lax">March</td>
<td class="tg-0lax">113</td>
<td class="tg-0lax">109</td>
<td class="tg-0lax">4.708333333333333</td>
<td class="tg-0lax">4.541666666666669</td>
<td class="tg-0lax">24</td>
</tr>
<tr>
<td class="tg-0lax">2020</td>
<td class="tg-0lax">April</td>
<td class="tg-0lax">98</td>
<td class="tg-0lax">81</td>
<td class="tg-0lax">4.083333333333329</td>
<td class="tg-0lax">3.375</td>
<td class="tg-0lax">24</td>
</tr>
<tr>
<td class="tg-0lax">2020</td>
<td class="tg-0lax">May</td>
<td class="tg-0lax">141</td>
<td class="tg-0lax">114</td>
<td class="tg-0lax">7.049999999999981</td>
<td class="tg-0lax">5.700000000000013</td>
<td class="tg-0lax">20</td>
</tr>
<tr>
<td class="tg-0lax">2020</td>
<td class="tg-0lax">June</td>
<td class="tg-0lax">130</td>
<td class="tg-0lax">121</td>
<td class="tg-0lax">6.5</td>
<td class="tg-0lax">6.049999999999988</td>
<td class="tg-0lax">20</td>
</tr>
<tr>
<td class="tg-0lax">2020</td>
<td class="tg-0lax">July</td>
<td class="tg-0lax">117</td>
<td class="tg-0lax">99</td>
<td class="tg-0lax">6.15789473684209</td>
<td class="tg-0lax">5.210526315789479</td>
<td class="tg-0lax">19</td>
</tr>
<tr>
<td class="tg-0lax">2020</td>
<td class="tg-0lax">August</td>
<td class="tg-0lax">126</td>
<td class="tg-0lax">117</td>
<td class="tg-0lax">6.299999999999986</td>
<td class="tg-0lax">5.850000000000015</td>
<td class="tg-0lax">20</td>
</tr>
<tr>
<td class="tg-0lax">2020</td>
<td class="tg-0lax">September</td>
<td class="tg-0lax">177</td>
<td class="tg-0lax">127</td>
<td class="tg-0lax">9.83333333333331</td>
<td class="tg-0lax">7.055555555555568</td>
<td class="tg-0lax">18</td>
</tr>
</tbody>
</table>
A couple columns are measures. They are defined below:
Average Assignments for Unique Orders per Clearance Officer = AVERAGEX(iDashUndAndComProcedure, DIVIDE(DISTINCTCOUNT(iDashUndAndComProcedure[Order Number Only]), DISTINCTCOUNT(iDashUndAndComProcedure[Clearance Officer])))
Average Assignments per Clearance Officer = AVERAGEX(iDashUndAndComProcedure, DIVIDE(DISTINCTCOUNT(iDashUndAndComProcedure[Order Number]), DISTINCTCOUNT(iDashUndAndComProcedure[Clearance Officer])))
The issue is the date in each point of the chart is acting as a filter, preventing the running total to work. If you change your result to:
VAR Result =
IF (
FirstVisibleDate <= LastDateWithOrders,
CALCULATE (
iDashUndAndComProcedure[Unique Order Count],
ALL(iDashUndAndComProcedure[Settlement Date]),
iDashUndAndComProcedure[Settlement Date] <= LastVisibleDate
)
)
It will clear the filters on Settlement Date and return you the correct value.
Related
I would like to draw a graph like this -
I have Graphviz code like this -
digraph G {
"test" [
label = <<table border="0" cellspacing="0">
<tr>
<td port="f0" border="1" bgcolor="darkorange">TEST</td>
<td port="f1" border="1" bgcolor="darkorange"></td>
</tr>
<tr>
<td port="f2" border="1" bgcolor="cyan">A</td>
<td>
<table border="0" cellspacing="0">
<tr><td port="f3" border="1" bgcolor="azure">A1</td></tr>
<tr><td port="f4" border="1" bgcolor="azure">A2</td></tr>
<tr><td port="f5" border="1" bgcolor="azure">A3</td></tr>
</table>
</td>
</tr>
<tr>
<td port="f5" border="1" bgcolor="gray">Else</td>
<td port="f6" border="1" bgcolor="gray"></td>
</tr>
</table>>
shape = "none"
];
}
But it gives the graph like this
Would you please suggest how can we tweak the code to achieve the objective - merging f0, f1 on top and f5,f6 at bottom?
You can use HTML <td>s with colspan and rowspan attributes in GraphViz. These allow one cell to span multiple columns and/or rows inside a table.
This also simplifies your digraph, as only one table is needed.
digraph G {
"test" [
label = <<table border="0" cellspacing="0">
<tr>
<td colspan="2" port="f0" border="1" bgcolor="darkorange">TEST</td>
</tr>
<tr>
<td rowspan="3" port="f5" border="1" bgcolor="blue">A</td>
<td port="f6" border="1" bgcolor="white">A1</td>
</tr>
<tr>
<td port="f6" border="1" bgcolor="white">A2</td>
</tr>
<tr>
<td port="f6" border="1" bgcolor="white">A3</td>
</tr>
<tr>
<td colspan="2" port="f0" border="1" bgcolor="grey">Else</td>
</tr>
</table>>
shape = "none"
];
}
This gives you the following basic output, which you can then customize for spacing, line colors, etc:
This one also works. what's is the difference?
digraph G {
"test" [
label = <<table border="0" cellspacing="0">
<tr><td colspan="2" port="f0" border="1" bgcolor="darkorange">TEST</td> </tr>
<tr><td rowspan="4" port="f5" border="1" bgcolor="blue">A</td></tr>
<tr><td port="f6" border="1" bgcolor="white">A1</td></tr>
<tr><td port="f6" border="1" bgcolor="white">A2</td></tr>
<tr><td port="f6" border="1" bgcolor="white">A3</td></tr>
<tr><td colspan="2" port="f0" border="1" bgcolor="grey">Else</td></tr>
</table>>
shape = "none"
];
}
I have a table like
<table class="tg">
<tr>
<th class="tg-0lax">date</th>
<th class="tg-0lax">organic</th>
<th class="tg-0lax">referrer</th>
<th class="tg-0lax">direct</th>
</tr>
<tr>
<td class="tg-0lax">01.01.2019</td>
<td class="tg-0lax">12345</td>
<td class="tg-0lax">123</td>
<td class="tg-0lax">23</td>
</tr>
<tr>
<td class="tg-0lax">25.01.2019</td>
<td class="tg-0lax">23456</td>
<td class="tg-0lax">234</td>
<td class="tg-0lax">34</td>
</tr>
<tr>
<td class="tg-0lax">03.03.2019</td>
<td class="tg-0lax">34567</td>
<td class="tg-0lax">345</td>
<td class="tg-0lax">56</td>
</tr>
<tr>
<td class="tg-0lax">15.04.2019</td>
<td class="tg-0lax">45678</td>
<td class="tg-0lax">456</td>
<td class="tg-0lax">78</td>
</tr>
</table>
I want to get the data into this view, where all data are placed into the same three columns, not dependently of whether points in the first column are repeated:
<table class="tg">
<tr>
<th class="tg-0lax">type</th>
<th class="tg-0lax">source</th>
<th class="tg-0lax">date</th>
</tr>
<tr>
<td class="tg-0lax">organic</td>
<td class="tg-0lax">12345</td>
<td class="tg-0lax">01.01.2019</td>
</tr>
<tr>
<td class="tg-0lax">referrer</td>
<td class="tg-0lax">123</td>
<td class="tg-0lax">01.01.2019</td>
</tr>
<tr>
<td class="tg-0lax">direct</td>
<td class="tg-0lax">23</td>
<td class="tg-0lax">01.01.2019</td>
</tr>
<tr>
<td class="tg-0lax">organic</td>
<td class="tg-0lax">23456</td>
<td class="tg-0lax">25.01.2019</td>
</tr>
<tr>
<td class="tg-0lax">referrer</td>
<td class="tg-0lax">234</td>
<td class="tg-0lax">25.01.2019</td>
</tr>
<tr>
<td class="tg-0lax">direct</td>
<td class="tg-0lax">34</td>
<td class="tg-0lax">25.01.2019</td>
</tr>
<tr>
<td class="tg-0lax">organic</td>
<td class="tg-0lax">34567</td>
<td class="tg-0lax">03.03.2019</td>
</tr>
<tr>
<td class="tg-0lax">referrer</td>
<td class="tg-0lax">345</td>
<td class="tg-0lax">03.03.2019</td>
</tr>
<tr>
<td class="tg-0lax">direct</td>
<td class="tg-0lax">56</td>
<td class="tg-0lax">03.03.2019</td>
</tr>
<tr>
<td class="tg-0lax">organic</td>
<td class="tg-0lax">45678</td>
<td class="tg-0lax">15.04.2019</td>
</tr>
<tr>
<td class="tg-0lax">referrer</td>
<td class="tg-0lax">456</td>
<td class="tg-0lax">15.04.2019</td>
</tr>
<tr>
<td class="tg-0lax">direct</td>
<td class="tg-0lax">78</td>
<td class="tg-0lax">15.04.2019</td>
</tr>
</table>
The "normal" transposing is pretty close to what I want, but even not exactly this, and I miss the point, how to pivot the data.
Another one example:
Got an error:
What I'm doing wrong? The formula is:
=ARRAYFORMULA({"type","source","date";SPLIT(TRANSPOSE(SPLIT(CONCATENATE(IF(B2:D<>"","♠"&B1:D1&"♦"&B2:D&"♦"&A2:A, )),"♠")),"♦")})
The line breaks are from the formula away - I've deleted them. Could the error cause be that my Google Spreadsheets used in Germany - formula language issue?
=ARRAYFORMULA({"type", "source", "date";
SPLIT(TRANSPOSE(SPLIT(CONCATENATE(IF(B2:D<>"",
"♠"&B1:D1&"♦"&B2:D&"♦"&A2:A, )), "♠")), "♦")})
I am trying to display a hierarchical table as a normal table.
model.py
class Dimension_value(MPTTModel):
name = models.CharField(max_length = 200, null=True, blank = True, default = '')
parent = TreeForeignKey("self", on_delete=models.CASCADE, null=True, blank=True, related_name="children")
class MPTTMeta:
order_insertion_by = ['name']
def __str__(self):
return self.name
views.py
def show_genres(request):
return render(request, "accounts/dimension_detail.html", {'dimensions': Dimension_value.objects.all()})
dimension_detail.html
<div class="container-fluid">
<div class="card">
<div class="card-body">
<h2>My dimensions</h2>
{% load mptt_tags %}
<ul>
{% recursetree dimensions %}
<li>
{{ node.name }}
{% if not node.is_leaf_node %}
<ul class="children">
{{ children }}
</ul>
{% endif %}
</li>
{% endrecursetree %}
</ul>
</div>
</div></div>
Using django-mptt the lists show just fine. However I have no idea how to display this in a normal table.
For example
Europe|The Netherlands|Noord-Holland
Europe|The Netherlands|Zuid-Holland
Europe|Belgium|Vlaanderen
what I currently get
<table>
<thead>
<tr>
<th class="id orderable">ID</th>
<th class="name orderable">Name</th>
<th class="orderable parent">Parent</th>
<th class="asc lft orderable">Lft</th>
<th class="orderable rght">Rght</th>
<th class="asc orderable tree_id">Tree Id</th>
<th class="level orderable">Level</th>
</tr>
</thead>
<tbody>
<tr class="even">
<td class="id">6</td>
<td class="name">Asia</td>
<td class="parent">—</td>
<td class="lft">1</td>
<td class="rght">4</td>
<td class="tree_id">1</td>
<td class="level">0</td>
</tr>
<tr class="odd">
<td class="id">8</td>
<td class="name">Japan</td>
<td class="parent">Asia</td>
<td class="lft">2</td>
<td class="rght">3</td>
<td class="tree_id">1</td>
<td class="level">1</td>
</tr>
<tr class="even">
<td class="id">5</td>
<td class="name">Europe</td>
<td class="parent">—</td>
<td class="lft">1</td>
<td class="rght">8</td>
<td class="tree_id">2</td>
<td class="level">0</td>
</tr>
<tr class="odd">
<td class="id">7</td>
<td class="name">Belgium</td>
<td class="parent">Europe</td>
<td class="lft">2</td>
<td class="rght">7</td>
<td class="tree_id">2</td>
<td class="level">1</td>
</tr>
<tr class="even">
<td class="id">9</td>
<td class="name">Vlaanderen</td>
<td class="parent">Belgium</td>
<td class="lft">3</td>
<td class="rght">4</td>
<td class="tree_id">2</td>
<td class="level">2</td>
</tr>
<tr class="odd">
<td class="id">10</td>
<td class="name">Wallonie</td>
<td class="parent">Belgium</td>
<td class="lft">5</td>
<td class="rght">6</td>
<td class="tree_id">2</td>
<td class="level">2</td>
</tr>
</tbody>
</table>
I have a table like following:
<style type="text/css">
.tg {border-collapse:collapse;border-spacing:0;}
.tg td{font-family:Arial, sans-serif;font-size:14px;padding:10px 5px;border-style:solid;border-width:1px;overflow:hidden;word-break:normal;}
.tg th{font-family:Arial, sans-serif;font-size:14px;font-weight:normal;padding:10px 5px;border-style:solid;border-width:1px;overflow:hidden;word-break:normal;}
.tg .tg-baqh{text-align:center;vertical-align:top}
</style>
<table class="tg">
<tr>
<th class="tg-baqh">Store Name</th>
<th class="tg-baqh">Week Number</th>
<th class="tg-baqh">Sales</th>
<th class="tg-baqh">Sales-LY</th>
</tr>
<tr>
<td class="tg-baqh">Store A</td>
<td class="tg-baqh">1</td>
<td class="tg-baqh">20</td>
<td class="tg-baqh">15</td>
</tr>
<tr>
<td class="tg-baqh">Store A</td>
<td class="tg-baqh">2</td>
<td class="tg-baqh">25</td>
<td class="tg-baqh">20</td>
</tr>
<tr>
<td class="tg-baqh">Store A</td>
<td class="tg-baqh">3</td>
<td class="tg-baqh">30</td>
<td class="tg-baqh">25</td>
</tr>
<tr>
<td class="tg-baqh">Store B</td>
<td class="tg-baqh">1</td>
<td class="tg-baqh">15</td>
<td class="tg-baqh">10</td>
</tr>
<tr>
<td class="tg-baqh">Store B</td>
<td class="tg-baqh">2</td>
<td class="tg-baqh">15</td>
<td class="tg-baqh">15</td>
</tr>
<tr>
<td class="tg-baqh">Store B</td>
<td class="tg-baqh">3</td>
<td class="tg-baqh">20</td>
<td class="tg-baqh">15</td>
</tr>
<tr>
<td class="tg-baqh">Store C</td>
<td class="tg-baqh">1</td>
<td class="tg-baqh">30</td>
<td class="tg-baqh">25</td>
</tr>
<tr>
<td class="tg-baqh">Store C</td>
<td class="tg-baqh">2</td>
<td class="tg-baqh">0</td>
<td class="tg-baqh">20</td>
</tr>
<tr>
<td class="tg-baqh">Store C</td>
<td class="tg-baqh">3</td>
<td class="tg-baqh">25</td>
<td class="tg-baqh">20</td>
</tr>
</table>
I would like to return (lets' say) a pivot table with
Salex IDX = SUM(Sales)/SUM(Sales-LY) as a measure, ignoring the data points for "Week 2 for Store C".
So it's not a filter on just Week Number or Store, but its a filter on specific row(s) identified by multiple parameters.
Essentially, i would like to get 'like for like' results, excluding any weeks where Sales or Sales-LY columns are zero(or null)
Any ideas?
I would add a calculated column to concatenate Store and Week, something like this:
=[Store Name]&", Week: "&[Week Number]
Then you can use a filter or slicer to exclude the Store & Week combination you want.
I am trying to screen scrape another application using the below code in Coldfusion.
<cfhttp url="https://intra.att.com/itscmetrics/EM2/LTMR.cfm" method="get" username="uvwxyz" password="abcdef">
<cfhttpparam type="url" name="LTMX" value="Andre Fuetsch / Shelly K Lazzaro">
</cfhttp>
<cfset myDocument = cfhttp.fileContent>
<cfoutput>
#myDocument#
</cfoutput>
Now when I run my cfm page, iam able to access the desitination page, with the above code.
The destination page looks like below.
A part of the source code of this is as below.
<table border="1" width=99% style="border-collapse:collapse;">
<thead>
<td colspan="12" class="drpmainheader1_2">LTM Detail Report for Andre Fuetsch / Shelly K Lazzaro</td>
<tr align="center">
<th class="ptitles">Liaison Name</th>
<th class="ptitles">Application Acronym</th>
<th class="ptitles">MOTS ID</th>
<th class="ptitles">Priority</th>
<th class="ptitles">MC</th>
<th class="ptitles">DR Exercise</th>
<th class="ptitles">ARM/SRM Maintenance</th>
<th class="ptitles">ARM/SRM Creation</th>
<th class="ptitles">Backup & Recovery Certification</th>
<th class="ptitles">Interface Certification</th>
<th class="ptitles">AIA Compliance</th>
</tr>
</thead>
<tbody>
<tr>
<td class="drpdetailtablerowdetailleft">Lynette M Acosta</td>
<td class="drpdetailtablerowdetailleft">AABA</td>
<td class="drpdetailtablerowdetail">9710</td>
<td class="drpdetailtablerowdetail">5</td>
<td class="drpdetailtablerowdetail">NMC</td>
<td class="drpdetailtablerowdetail">Compliant</td> <td class="drpdetailtablerowdetail">Compliant</td> <td class="drpdetailtablerowdetail">Compliant</td> <td class="drpdetailtablerowdetail">Compliant</td> <td class="drpdetailtablerowdetail">Compliant</td> <td class="drpdetailtablerowdetail">Compliant</td>
</tr>
</tbody>
<tbody>
<tr>
<td class="drpdetailtablerowdetailleft">Lynette M Acosta</td>
<td class="drpdetailtablerowdetailleft">ABS RECON+</td>
<td class="drpdetailtablerowdetail">13999</td>
<td class="drpdetailtablerowdetail">3</td>
<td class="drpdetailtablerowdetail">NMC</td>
<td class="drpdetailtablerowdetail">Compliant</td> <td class="drpdetailtablerowdetail">Compliant</td> <td class="drpdetailtablerowdetail">Compliant</td> <td class="drpdetailtablerowdetail">Compliant</td> <td class="drpdetailtablerowdetail">Compliant</td> <td class="drpdetailtablerowdetail">Compliant</td>
</tr>
</tbody>
I am not good with regex in coldfusion, Can anyone please guide me or give me any starting points as to how to extract the data from the html table using Coldfusion? I do not have access to the DB. Hope this is clear.
Parsing HTML using regex? You'll have more options if you use the jsoup HTML Parser w/ColdFusion. Jsoup uses jQuery-like DOM selectors and can quickly convert the HTML table data into arrays.
http://jsoup.org/
Here are some related articles & sample code:
http://www.raymondcamden.com/index.cfm/2012/4/6/jsoup-adds-jQuerylike-parsing-in-Java
http://www.bennadel.com/blog/2358-Parsing-Traversing-And-Mutating-HTML-With-ColdFusion-And-jSoup.htm
http://pastebin.com/U6A86mSi