FAQ/UserGuides/15.3-Advanced-Expressions.md
... ...
@@ -1,32 +1,40 @@
1
-#15.3 Advanced Expressions
2
-
3
-### Ratios
4
-
5
-We can use arithmetic to get a percentage of one value compared to an aggregate value.
6
-
7
-**The following expression determines the percentage of an order’s cost paid for shipping:**
8
-``([Orders].[Freight])/(([Order Details].[UnitPrice]) * ([Order Details].[Quantity])+([Orders].[Freight]))``
9
-
10
-![expressions5](http://wiki.izenda.us/FAQ/FAQ/expressions5.png)
11
-
12
-![expressions6](http://wiki.izenda.us/FAQ/FAQ/expressions6.png)
13
-
14
-The above expression would return a decimal output. For example, if Freight were ``$10`` and the total sum of ``UnitPrice*Quantity`` were ``$90``, then ``10/(90+10) = .1`` as our result. Izenda will read this as a numeric value, so all that is necessary to turn this into a percentage is to select the ‘%’ format from the Formats dropdown for this field.
15
-
16
-### Caution: The Limits of Expressions
17
-
18
-However, this is where we encounter a limitation on expressions. The above expression will produce correct results for each product in the order. Since the data necessary for this expression comes from multiple data sources (Orders, Products, and Order Details in the Northwind DB) it is necessary to use key variables – in this case, OrderID – to link the tables. Also, each OrderID has multiple associated ProductID to represent multiple products in each order. It is not possible to specify variables from within an expression. The net result of our expression will produce the ``UnitPrice*Quantity`` for a single 'ProductID' on each line. It will not sum the total ``UnitPrice*Quantity`` values for multiple products within an order.
19
-
20
-If we break the total equation into steps, the problem becomes clearer:
21
-
22
-1. Calculate UnitPrice*Quantity for each ProductID within an OrderID.
23
-2. Sum these calculated values into a hypothetical TotalUnitPrice for the OrderID.
24
-3. Add Freight to TotalUnitPrice and divide Freight by this value to get a percentage freight cost of total order cost.
25
-
26
-Since expressions cannot create fields, but only display calculations based on fields, expressions cannot execute step 2. Steps 1 and 2 should be calculated in a view, which would create a computed column that can be used in an expression for step 3.
27
-
28
----
29
-
30
-[[15.0 Expressions in Izenda]]
31
-
32
-[[User Guides|http://wiki.izenda.us/FAQ/UserGuides]]
1
+#Dynamically Changing Data Sources
2
+
3
+[[_TOC_]]
4
+
5
+##Question
6
+
7
+How can I change the data source I'm using for my reports on the fly?
8
+
9
+##Answer
10
+
11
+You can change the data source for individual reports by overriding the [[PreExecuteReportSet|/FAQ/PreExecuteReportSet]] method. Here is the source code for changing data sources:
12
+
13
+```
14
+public override void PreExecuteReportSet(Izenda.AdHoc.ReportSet reportSet)
15
+{
16
+ base.PreExecuteReportSet(reportSet);
17
+ string orig = reportSet.Source;
18
+ string target = "[dbo].[Orders2]";
19
+
20
+ if(!orig.Contains("Orders")) {
21
+ return; //check for strings like "Orders". If that's not found, we return.
22
+ }
23
+ foreach (JoinedTable jt in reportSet.JoinedTables)
24
+ {
25
+ jt.TableName = jt.TableName.Replace(orig, target);
26
+ }
27
+ foreach (Report r in reportSet.Reports.AllValues)
28
+ {
29
+ foreach (Field f in r.Fields)
30
+ {
31
+ f.ColumnName = f.ColumnName.Replace(orig, target);
32
+ }
33
+ }
34
+
35
+ foreach (Filter f in reportSet.Filters)
36
+ {
37
+ f.Column = f.Column.Replace(orig, target);
38
+ }
39
+}
40
+```
... ...
\ No newline at end of file