简体   繁体   English

SSRS - 根据where子句在表达式中显示字段?

[英]SSRS - show field in expression based on where clause?

I have a data table that looks like the below.我有一个如下所示的数据表。 This shows the top 3 subcallcategories based on the amount of calls.这显示了基于呼叫量的前 3 个子呼叫类别。 The "order" column is a row number that shows which order the subcallcategory was in based on the calls. “order”列是一个行号,显示基于调用的 subcallcategory 所在的顺序。

I am trying to write some DAX in SSRS which displays the following我正在尝试在 SSRS 中编写一些 DAX,它显示以下内容

Anxiety was the most common counselling call, followed by Work Related Stress and Bereavement焦虑是最常见的咨询电话,其次是工作相关压力和丧亲

I have written the below code however it doesn't seem to be picking up the last 2 categories?我已经编写了下面的代码,但是它似乎没有选择最后两个类别? Anyone have any ideas what I am doing wrong?有人知道我做错了什么吗?

=IIf(Fields!Order.Value = "1" and Fields!Category.Value = "Counselling", Fields!SubCallCategory.Value, "") & 
    " was the most common counselling call, followed by " & 
    IIf(Fields!Order.Value = "2" and Fields!Category.Value = "Counselling", Fields!SubCallCategory.Value, "") & 
    " and " & IIf(Fields!Order.Value = "3" and Fields!Category.Value = "Counselling", Fields!SubCallCategory.Value, "")

在此处输入图像描述

Below is my current output下面是我目前的 output

在此处输入图像描述

As Alan mentioned, your expression is just looking at a single row of data.正如 Alan 所提到的,您的表达只是查看单行数据。

You would need to put this expression in a table with Grouping by Category.您需要将此表达式放在按类别分组的表中。

Then you would look for the ones in your ORDER and use that Sub Cat value.然后,您将在您的 ORDER 中查找那些并使用该 Sub Cat 值。 I use MAX and NULL to get matching values like我使用 MAX 和 NULL 来获得匹配值,例如

=MAX(IIf(Fields!Order.Value = 1, Fields!SubCallCategory.Value, NOTHING)) & 
    " was the most common " & Fields!Category.Value & " call, followed by " & 
    MAX(IIf(Fields!Order.Value = 2, Fields!SubCallCategory.Value, NOTHING)) & 
    " and " & MAX(IIf(Fields!Order.Value = 3, Fields!SubCallCategory.Value, NOTHING))

The MAX will get the SubCat value over NOTHING (SSRS for NULL) for the ones in the right ORDER.对于正确 ORDER 中的那些,MAX 将获得超过 NOTHING(SSRS 为 NULL)的 SubCat 值。

This would give one line for Counselling and one for Legal.这将为咨询提供一条线路,为法律提供一条线路。

You could also add the totals in with您还可以将总数添加到

MAX(IIf(Fields!Order.Value = 1, Fields!Calls.Value, 0))

I assume your ORDER field is an INTEGER and doesn't need the quotes.我假设您的 ORDER 字段是 INTEGER 并且不需要引号。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM