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
768 views
in Technique[技术] by (71.8m points)

reporting services - Adding values to a Report when there is no Data in query SSRS

I have a query that returns Sales representatives number, Category, Sales.

The result is something like this:

enter image description here

There are 4 categories called G1,G2,G3,G4.

As you can see the Sales representative 11 sold 10 each category (Yellow rows). But Representative 12 sold only for category G3 and G4.

The idea is to show in the report all the categories and populate with 0 all those who did not sell on that particular category.

It must be grouped by Sales Representative so if you make a tablix grouping by Sales Representatives you will have something like this:

enter image description here

But you want something like this:

enter image description here

Is there any expression I could use to add these?

What I did so far is to create a group, that group of course are my Sales representatives and combine the cells for that Column and created a Row group for each category, is something like this:

enter image description here

But if you execute that report it will repeat all categories G1,G2... For each time that category exists for that particular Sales Representative.

Another problem is, how can you evaluate The hardcoded category in your report if it does not exist in your datasource you cant make Iif("G1" = Fields!Category.Value,Fields!Sales.Value,"0") as you are not comparing G1 with Null or IsNothing, you are comparing what it exists.

See Question&Answers more detail:os

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

1 Reply

0 votes
by (71.8m points)

I think you can achieve this smoothly using T-SQL at query level. I don't know why you don't use the simplest way to apply this kind of logic since in T-SQL you can use almost every logic.

However I like this kind of challenges so I come with this possible solution.

This is my sample dataset:

enter image description here

In SSRS dataset (not in T-SQL) I've added a calculated field called Another

enter image description here

Another field is set to the below expression:

=Fields!SalesRep.Value & "-" & Fields!Category.Value

I've added a tablix with the following data arrangement

enter image description here

As I mentioned before category field is hardcoded, the right column with Sales is set to this expression:

=iif(IsNothing(lookup(Fields!SalesRep.Value & "-" & ReportItems!Textbox62.Value,
Fields!Another.Value,Fields!Sales.Value,"DataSet7")),0,
lookup(Fields!SalesRep.Value & "-" & ReportItems!Textbox62.Value,
Fields!Another.Value,Fields!Sales.Value,"DataSet7"))

Note: ReportItems!Textbox62.Value corresponds to textbox where G1 was hardcoded. You have to replace the textbox reference for the corresponding in your tablix for every category.

It will preview the below tablix.

enter image description here

Let me know if this was helpful.


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

...