Quantcast
Channel: SQL Server Reporting Services, Power View forum
Viewing all articles
Browse latest Browse all 28687

Percentage of a column based on counts and sum of distinct values

$
0
0

Hey All,

My current report looks like this:

Id VAL   Name   SNum   State   Count
1  $100  Lkt40    1294    S      4
1  $100  Lkt41    6321    S      4
1  $100  Lkt42    1897    S      4
1  $100  Lkt43    8374    A      4
2  $200  Lkt44    1344    C      3
2  $200  Lkt45    1122    U      3
2  $200  Lkt46    1066    C      3
3  $300  Lkt47    9890    S      2
3  $300  Lkt48    1323    T      2

This basically means that Id=1 has TotalCount=4, where Count("S")=3 and Count("A")=1 (SoCOUNT(S+A) = 4)

I need to get this in my 2nd tablix below my main report that references my 1st dataset (i.e. dataset for main report):

State   Count   Percent
  S        4       4/(Sum(Distinct(CountOfId)(i.e. 4+3+2 count for each Id)
  A        1       1/9--Since Id=1 has count 4, Id=2 has count 3, Id=3 has count 2
  C        2       2/9
  U        1       1/9
  T        1       1/9

In my 2nd report (a matrix below my main report, I have succeeded, to get the Counts(States) right. I have a RowGroup On State, and have added a Count(State) column that gives me the counts of States correctly. Getting the percentage is being troublesome. I tried to use RowNumber function to assign each row in my main dataset a number, and then grabbing the count of each row, where RowNum=1.

But I am facing problems when I use this expression for my percentage:

= Count(Fields!State.Value) / (Sum(Iif(Fields!RowNumber.Value=1,Fields!Count.Value,0))

It gives me wrong results, in this case "(Sum(Iif(Fields!RowNumber.Value=1,Fields!Count.Value,0))" should give me answer as 9. In my actual scenario, resuls are way off.


Viewing all articles
Browse latest Browse all 28687


<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>