SSRS : New calculated field based on where condition

我只是一个虾纸丫 提交于 2019-12-13 04:59:15

问题


I'm new to SSRS reporting and I'm need of help...

I have a dataset with fields "Process", "Level" and "Workweek"

Process Level  WW
------- -----  --
Test    Lvl_0   3
Test    Lvl_1  28
Test    Lvl_2  48
Samp    Lvl_0  10
Samp    Lvl_1  39
Samp    Lvl_2  51

What I want now is to create two more calculated fields called Start_WW and Pro_Start that has the values from WW field.

WW of Lvl_0 is considered to be the Process_Start.

the logic is something like

Process Level  WW Start_WW Pro_Start
------- -----  -- -------- ---------
Test    Lvl_0   3    0       3
Test    Lvl_1  28    3       3
Test    Lvl_2  48   28       3
Samp    Lvl_0  10    0      10
Samp    Lvl_1  39   10      10
Samp    Lvl_2  51   39      10

I know it is similar to SQL

Update Table SET Start_WW=(Select WW from Table where Level='Lvl_0') where Level='Lvl_1'

Update Table SET Proc_Start=(Select WW from Table where Level='Lvl_0')

I'm not sure how to write the expression for it. Pls help me.

Thanks in Advance!!


回答1:


If the Start_WW is simply the previous WW then you don't even need a calculated field; you can just use the Previous() function in the expression for the table's cell:

=IIF(Fields!Process.Value = Previous(Fields!Process.Value), Previous(Fields!WW.Value), 0)

For the Pro_Start, you can add this to your SQL:

SELECT MyTable.Process, MyTable.Level, MyTable.WW, Start.Pro_Start 
FROM MyTable 
INNER JOIN (
    SELECT Process, Level, MIN(WW) AS Pro_Start 
    FROM MyTable 
    GROUP BY Process, Level
) Start ON MyTable.Process = Start.Process AND MyTable.Level = Start.Level

With no access to the query, then you can get Pro_Start via a Lookup():

=Lookup(Fields!Process.Value, Fields!Process.Value, Fields!WW.Value, "MyDataset")

The Lookup() will return the first instance of the Process and give you the WW of that row.



来源:https://stackoverflow.com/questions/26625721/ssrs-new-calculated-field-based-on-where-condition

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!