【问题标题】:Correct expression with IIF does not work使用 IIF 的正确表达式不起作用
【发布时间】:2016-03-18 14:40:48
【问题描述】:

我使用在线 CRM。这就是我使用 fetchXML 的原因。这是我的收获:

`<fetch aggregate="true" distinct="false" no-lock="false" mapping="logical">
<entity name="lead" >
<attribute name="fullname" alias="lead_name" groupby="true" />
<attribute name="new_bpf_stage" alias="lead_stage" groupby="true" />
<attribute name="new_substep" alias="lead_substep" groupby="true" />
<attribute name="leadid" alias="lead_id" groupby="true" />
<filter type="and" >
  <condition attribute="createdon" operator="ge" value="@PeriodBeginning" />
  <condition attribute="createdon" operator="le" value="@PeriodEnding" />
</filter>
<link-entity name="new_duration_life_cycle"    from="new_lead_duration_life_cycleid" to="leadid" link-type="outer" >
  <attribute name="new_duration" alias="current_duration" groupby="true" />
  <attribute name="new_active" alias="current_is_active" groupby="true" />
  <attribute name="new_transition_date" alias="current_transition_date" aggregate="max" />
  <filter type="and" >
    <condition attribute="new_active" operator="eq" value="1" />
  </filter>
</link-entity>
<link-entity name="new_duration_life_cycle"    from="new_lead_duration_life_cycleid" to="leadid" link-type="outer">
  <attribute name="new_duration" alias="duration_sum" aggregate="sum" />
</link-entity>
</entity>

` 这是表达式代码:

=IIF(Fields!current_is_activeValue.Value = "True", 
DATEDIFF ("d", CDate(Format(Fields!current_transition_dateValue.Value, "MM.dd.yyyy hh:mm:ss")), Now()) + 
IIF(DATEDIFF ("h", CDate(Format(Fields!current_transition_dateValue.Value, "MM.dd.yyyy hh:mm:ss")), Now()) Mod 24 > 8, 
    8, 
    (DATEDIFF ("h", CDate(Format(Fields!current_transition_dateValue.Value, "MM.dd.yyyy hh:mm:ss")), Now())) Mod 24)/8 +
IIF(Fields!current_duration.Value = "",
    0,  
    CDbl(Replace(Fields!current_duration.Value,",",".")))
,
Fields!current_duration.Value)

在这段代码中,我检查了一些属性,如果它的值为真,我计算字段值。但如果某些值不存在(如果 current_is_activeValue.Value = ""),则在相应的单元格中会显示错误。 但错误不得存在:必须显示 Fields!current_duration.Value 必须为“”。看起来表达式无论如何都会计算两种 IIF 情况。 有没有人遇到这样的问题?

【问题讨论】:

  • "d""h" 在 SSRS 中无效 DATEDIFF 间隔,您可以使用 DAYHOURDateInterval.DayDateInterval.Hour。请参阅文档here。另外,我不确定格式字符串中的句点是否允许。您可能需要将"MM.dd.yyyy hh:mm:ss" 更改为"MM/dd/yyyy hh:mm:ss""MM-dd-yyyy hh:mm:ss"

标签: reporting-services fetchxml ssrs-expression


【解决方案1】:

尝试分解你的表达式以可视化 IFFs:

第一个IIF的IF条件

 =IIF(Fields!current_is_activeValue.Value = "True", 

这整个部分是第一个 IIF 的 THEN 子句。如您所见,所有三个值都已添加,因此将计算该子句中的两个 IIF。

DATEDIFF ("d", CDate(Format(Fields!current_transition_dateValue.Value, "MM.dd.yyyy hh:mm:ss")), Now()) 
+ 
IIF(DATEDIFF ("h", CDate(Format(Fields!current_transition_dateValue.Value, "MM.dd.yyyy hh:mm:ss")), Now()) Mod 24 > 8, 
8, 
(DATEDIFF ("h", CDate(Format(Fields!current_transition_dateValue.Value, "MM.dd.yyyy hh:mm:ss")), Now())) Mod 24)/8 
+
IIF(Fields!current_duration.Value = "",    0,     CDbl(Replace(Fields!current_duration.Value,",","."))) 

第一个 IIF 的其他内容

,
Fields!current_duration.Value)

它正在计算两个 IIF。您可能需要编辑表达式。

【讨论】:

    【解决方案2】:

    你可以在这里http://msxrmtools.com在线测试FetchXML

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2010-11-03
      • 1970-01-01
      • 2016-06-14
      • 2019-10-27
      • 2017-08-15
      • 1970-01-01
      相关资源
      最近更新 更多