Comparing sold quantity and harvested quantity which are at different roster levels

Hi,

I want to check that the quantity of crops sold or quantity of pre-harvest lost is below or equal to the quantity harvested. I created variables equal to the harmonized quantity in kg for each crop-state-unit codes using a lookup table. I am having some problems comparing those values because they are at different roster levels. More specifically, the quantity harvested (harvest_crop_plot) is in a 2 level roster at plot-crop level, while the quantities lost (lost_crop) or sold are at the crop level (sold_crop).

So, I want to add a validation condition on lost_crop and sold_crop. The issue is that I need a comparison value, the sum of the harvested quantities across plots, but per crop and to "call" it in a variable in the crop-level.

Thanks,

Bordalo

See section BURGERS in the “Public example User questions and common patterns”

Hi Sergiy,
The example given in Burgers does not help much in our case.
Bordalo and I are trying to create a variable Hj (1 level roster, crop level) equal to the sum of harvested quantity hj of a crop j across all plots (2 level roster, plot-crop level)

  • Plot_roster
    - Crop_roster1
    * hj = Harvested quartity of crop j

  • Crop_roster2
    * Hj = sum of hj = plot_roster.Sum(x=>x[crop_roster1].hj)

This is not a correct syntax as we do not know how to refer a value inside a 2 level roster and specifically to the value of hj corresponding to the same crop code in Crop_roster1 and in Crop_roster2, which should be the same (the two rosters use different source questions but same codes of crops).

thanks for the help.
Claire

Dear Claire,

Correct me if I am wrong, but following your explanation, you have a new fixed set items roster of all your crops called Crop_roster2 at the main level of your interview (Of which you probably only enable those crops that have been named on any plot). In different words: You obtain information about inputs and harvest of each crop on each plot but then BULK all crops of the same kind to ask about the sales?

If this is more or less the case try the following syntax:
Variable ‘Hj’ in Crop_roster2 (Double):

Plot_roster.Where(x=>x.CROPQ!=null && x.CROPQ.Contains(@rowcode)).Sum(p=>p.Crop_roster1[@rowcode].hj)

CROPQ== The question on each plot that asks which crops have been planted on plot XYZ.

Where(x=>x.CROPQ!=null && x.CROPQ.Contains(@rowcode)) takes care that you are skipping the plots in which maybe the crop question has not been enabled (For whatever reason). Ignore this part if there is no such question in your plotroster.

Of course, you need to make sure that the option codes of your crops in Crop_roster2 align with the codes used in Crop_roster1.

Hope this is of help!
Best
Peter

1 Like