Forum Discussion

tantle61's avatar
tantle61
New Member
2 years ago
Solved

Grouping to include missing values

I am using PBI report builder with row grouping.  I am trying to get a count of 3 catagories within a parent category.  The grouping works if the value is present but I would like to report zero counts too. For example, grouping by title, sub-grouping by status, I have 3 count groupings for status, "APPROVED", "REVOKED", "PENDING".  If "REVOKED" does not have any records, it does not report.  I need it to report zero.  How can I do this?

 

  • Found a solution: 

    select id, review_name, updated_dt,

    (select count(*) from
    ara.review_entry re
    where re.review_id = r.id and re.review_decision = 'APPROVED'
    ) as approved,

    (select count(*) from
    review_entry re
    where re.review_id = r.id and re.review_decision = 'REVOKED'
    ) as revoked,

    (select count(*) from
    review_entry re
    where re.review_id = r.id and re.review_decision = 'PENDING'
    ) as pending

    from review r

3 Replies

  • Anonymous's avatar
    Anonymous
    Not applicable

    Hi tantle61 ,

    Please have a try.

    =IIF(Count(Fields!Status.Value, "DataSet1", Recursive) = 0, 0, Count(IIF(Fields!Status.Value = "REVOKED", 1, Nothing), "DataSet1", Recursive))

    In this example, is the name of the dataset that contains the data you want to count. The function is used twice: once to check if there are any records for the “REVOKED” category, and again to count the number of records for the “REVOKED” category if there are any. The function is used to return a value of 0 if there are no records for the “REVOKED” category.DataSet1CountIIF

    You can modify this expression to count the number of records for other categories as well. Simply replace with the name of the category you want to count."REVOKED"

    Expression examples in paginated reports - Microsoft Report Builder & Power BI Report Builder | Microsoft Learn

    Count function in a paginated report - Microsoft Report Builder & Power BI Report Builder | Microsoft Learn

     

     

    How to Get Your Question Answered Quickly 

     

    If it does not help, please provide more details with your desired output and pbix file without privacy information (or some sample data) .

     

    Best Regards
    Community Support Team _ Rongtie

    If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

     

     

     

     

  • As in the examples below, the "REVOKED" value is missing from the grouping for "test 123" because this value is missing from the data.  I want to report the zero value as shown in the other image.  I tried this but got the same results as before 

    =IIF(Count(Fields!decision.Value, "Review", Recursive) = 0, 0,
    Count(IIF(Fields!decision.Value= "REVOKED", 1, Nothing), "Review", Recursive))

  • Found a solution: 

    select id, review_name, updated_dt,

    (select count(*) from
    ara.review_entry re
    where re.review_id = r.id and re.review_decision = 'APPROVED'
    ) as approved,

    (select count(*) from
    review_entry re
    where re.review_id = r.id and re.review_decision = 'REVOKED'
    ) as revoked,

    (select count(*) from
    review_entry re
    where re.review_id = r.id and re.review_decision = 'PENDING'
    ) as pending

    from review r