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

徘徊边缘 提交于 2019-12-02 06:30:53

问题


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

The result is something like this:

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:

But you want something like this:

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:

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.


回答1:


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:

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

Another field is set to the below expression:

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

I've added a tablix with the following data arrangement

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.

Let me know if this was helpful.



来源:https://stackoverflow.com/questions/33282098/adding-values-to-a-report-when-there-is-no-data-in-query-ssrs

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