Conditional expressions in Matrix

RJPRJP
edited 10:07AM in FastReport .NET
I have a datasource with columns Name, Item, Count, Target.

I use in a matrix, so it appears something like this
------------|        Item       |
------------| Count   | Target  |
----------------------------------
Name       | [Count] | [Target]  |
----------------------------------

So, the Name is the row cell, Item is the column cell, and both Count and Target are data cells (CellsSideBySide is True)

My issue is that I want [Count] data cell to be highlighted if it is less than the [Target] data cell, but I just can't figure out the syntax for this.

I tried: Value < [datasource.Target]. But that didn't work (I think [datasource.Target] was always equal to the first row only, but hard to tell).
I tried: Value < (int)Matrix1.Value(1). But that didn't work either (not sure what it was doing, but certainly didn't highlight the data cells that it should have).

So what is the syntax for this?

Comments

  • edited 10:07AM
    use script, i modified sample from fastreport by adding Cell9_BeforePrint event, look at attached picture.

    note : in matrix report, cell is printed from left to right (to understand that, uncomment 'MessageBox' from script below).
    in your case, cell 'target' is highlighted.
      public class ReportScript
      {
        private void Cell9_BeforePrint(object sender, EventArgs e)
        {
          if (Cell9.Value == null)
            return;
          double a = (double) ((int)Cell6.Value);
          double b = (double) ((decimal) Cell9.Value / 1000);
    
          //MessageBox.Show(a.ToString() + " < " + b.ToString());
    
          if (a < b)
            Cell9.Fill = new SolidFill(Color.Fuchsia);
        }       
      }
    
  • RJPRJP
    edited January 2017
    That looked like it was going to work. But it didn't work for me.

    I think the issue is that I'm trying to highlight the count rather than the target, and perhaps the current row/column is not getting updated for all cells at the appropriate time.

    As an example, try to change your script so that it is the Items Sold that is highlighted rather than the Revenue (with the same condition). In other words change the cell9.Fill = ... lines to cell6.Fill...

    You'll see that it just ends up highlighting cells all over the place.
  • edited January 2017
    as i said before, cells are printed from left to right.
    if you want to highlight first cell when you are at second cell, it wont work because first cell already printed.
    so, in your case, switch the column, target | actual

Leave a Comment

Rich Text Editor. To edit a paragraph's style, hit tab to get to the paragraph menu. From there you will be able to pick one style. Nothing defaults to paragraph. An inline formatting menu will show up when you select text. Hit tab to get into that menu. Some elements, such as rich link embeds, images, loading indicators, and error messages may get inserted into the editor. You may navigate to these using the arrow keys inside of the editor and delete them with the delete or backspace key.