简体   繁体   中英

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. The "order" column is a row number that shows which order the subcallcategory was in based on the calls.

I am trying to write some DAX in SSRS which displays the following

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

在此处输入图像描述

As Alan mentioned, your expression is just looking at a single row of data.

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. I use MAX and NULL to get matching values like

=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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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