Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
920 views
in Technique[技术] by (71.8m points)

reporting services - Lookup function in SSRS report

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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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:

enter image description here

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...