You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

在Genexus Query Viewer中如何基于行总计(而非列总计)显示百分比?

How to Calculate an Attraction's Percentage of Row Total in GeneXus Query

Hey there! I’ve worked with GeneXus Query objects extensively, so let me break down exactly how to configure your query to show the percentage each attraction contributes to its parent row total (using the continent/country/attraction example from the Genexus Query Usage Example docs).

Step 1: Confirm Your Base Query Setup

First, make sure your query already has:

  • Grouping levels configured: Continent → Country → Attraction
  • A numeric measure field (e.g., TotalVisitors, Revenue) that you’re aggregating for each attraction.

Step 2: Add a Row Total Calculation Field

You’ll need to calculate the total for the parent group (in this case, the total for the country each attraction belongs to) using GeneXus’s built-in RowTotal() function:

  1. In your Query object, navigate to the Calculations tab.
  2. Create a new calculated field with this formula:
    RowTotal(YourMeasureField)
    
    Replace YourMeasureField with your actual aggregated numeric field (like TotalVisitors). Name this something clear, e.g., CountryTotal.

Step 3: Calculate the Percentage

Next, create another calculated field to compute the attraction’s share of the row total:

  1. Add a second calculated field with this formula (to avoid division-by-zero errors):
    IIF(RowTotal(YourMeasureField) = 0, 0, (YourMeasureField / RowTotal(YourMeasureField)) * 100)
    
    • The IIF check handles cases where a country has no recorded data for the measure.
    • Name this field AttractionPercentage or similar.
  2. Set the field’s display format to Percentage (adjust decimal places in the format settings—2 decimal places works well for readability).

Step 4: Configure Query Output

  • Go to the Output tab of your Query.
  • Add the new AttractionPercentage field alongside your existing columns (Continent, Country, Attraction, YourMeasureField, CountryTotal).
  • Rearrange columns to match your desired layout (e.g., Attraction → YourMeasureField → AttractionPercentage → CountryTotal).

Step 5: Test and Verify

Run the query to confirm accuracy:

  • For any attraction, its percentage should equal (AttractionMeasure / CountryTotal) * 100
  • Percentages for all attractions under a single country should sum to ~100% (accounting for minor rounding differences).

That’s it! This setup will give you the exact breakdown you’re looking for, matching the example result you referenced.

内容的提问来源于stack exchange,提问作者Rogelio Arosemena

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.28 06:26:38