Lookup function in SSRS report

会有一股神秘感。 提交于 2019-12-10 10:08:50

问题


I have one dataset Dataset1 and in that I am displaying data based on grouping. The data is like this

   CityColumn      CountColumn
   City1              5
   City2              3

The query of above datase is like this :

select count(*) as "CountColumn" from City group by CityColumn

Here in above dataset I have counted using grouping on CityColumn.

Now I have created another Dataset Dataset2 and in that The data is like this

  CityColumn
   City1
   City2
   City3

Now in dataset2 I have add one calculated field called TotalCount and used the Lookup Function the function is like this

=Lookup(CityColumn, CityColumn, CountColumn, "Dataset1")

but It gives me an error like

Lookup includes aggregate, rownumber, runningvalue, previous or lookup function. Aggregate, rownumber, runningvalue, previous or lookup function cannot be used in calculated field.


回答1:


The first two values of the lookup function must refer to an identifying value in a column. In your case the City names must be in both datasets. Think of that as a primary key. The third value is the one you want to display from the second dataset. So it should look more like this:

=Lookup(Fields!CityColumn.Value, Fields!CityColumn.Value, Fields!CountColumn.Value, "Dataset1")

Make sure that Dataset1 has the column named CountColumn that you are trying to lookup. Keep in mind that this only looks up individual rows, not aggregates. If you want to work with aggregates you can do that on top of the lookup function.

EDIT:

Since Lookup functions are not allowed in calculated fields, you'll need to use it in the Value expression in your pie chart. It should look like this:

Note that the lookup function has to be in an aggregate like a sum function for it to work as a chart value.




回答2:


Instead of adding it as a calculated field in the DataSet, simply add the expression into an empty column within the details rows of the report.



来源:https://stackoverflow.com/questions/17318939/lookup-function-in-ssrs-report

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