Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
glycine76
Frequent Visitor

Need help on dealing with category hierarchy count

Hello, 

 

Let's say I have a data structure like this

 

Level 1        Level 2          Status

A                    A1              Approved

A                   A2                 Approved

A                 A3                  Approved

B                    B1             Review

B                     B2              Approved

B                   B3                Review

C                  C1                Approved

C                 C2                Approved

C                C3                       Approved

 

Only when all items in level 2 are approved, level 1 items are approved. So how do I write a measure to count how many level 1 items are approved? 

Thanks for the help in advance!

2 ACCEPTED SOLUTIONS
TomMartens
Super User
Super User

Hey @glycine76 ,

 

this measure:

Measure = 
COUNTX(
    VALUES( 'Status'[Lvl1] )
    , var noOfRowsLvl2 = 
        COUNTROWS(
            CALCULATETABLE(
                VALUES( 'Status'[Lvl2] )
                , ALL( 'Status'[Lvl2] )
                , ALL( 'Status'[Status] )
            )
        )
    var noOfRowsApproved = 
        COUNTROWS(
                CALCULATETABLE(
                    FILTER( 
                        'Status'
                        , 'Status'[Status] = "Approved"
                    )
                    , ALL( 'Status'[Lvl2] )
                    , ALL( 'Status'[Status] )
                )
            )
    return
    IF( noOfRowsLvl2 = noOfRowsApproved , 1 , BLANK() )
)

Allows creating this table visual:
image.png

Please be aware that I enabled the option "Show items with no data" on the column Lvl1, this option does not affect the measure, but it helps to understand my sample data, and why Lvl1 = B is not considered "complete".

Hopefully, this provides what you are looking for.

 

Regards,

Tom

Use the table tool when you are providing simple sample data otherwise it will eat up time from people trying to help:
image.png



Did I answer your question? Mark my post as a solution, this will help others!

Proud to be a Super User!
I accept Kudos 😉
Hamburg, Germany

View solution in original post

v-jianboli-msft
Community Support
Community Support

Hi @glycine76 ,

 

If you are using matrix, please try:

Measure =
IF (
    ISINSCOPE ( 'Table'[Level 2] ),
    MAX ( 'Table'[Status] ),
    IF (
        COUNTROWS ( FILTER ( 'Table', [Status] = "Approved" ) )
            = COUNTROWS ( 'Table' ),
        "Approved",
        "Review"
    )
)

Final output:

vjianbolimsft_0-1675131187617.png

Best Regards,

Jianbo Li

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

View solution in original post

4 REPLIES 4
v-jianboli-msft
Community Support
Community Support

Hi @glycine76 ,

 

Could you tell me if your problem has been solved? If it is, kindly Accept it as the solution. More people will benefit from it. Or if you are still confused about it, please provide me with more details about your table and your problem or share me with your pbix file after removing sensitive data.

 

Refer to:

How to provide sample data in the Power BI Forum

How to Get Your Question Answered Quickly

 

Best Regards,

Jianbo Li

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

glycine76
Frequent Visitor

Thank you all! Very helpful!

v-jianboli-msft
Community Support
Community Support

Hi @glycine76 ,

 

If you are using matrix, please try:

Measure =
IF (
    ISINSCOPE ( 'Table'[Level 2] ),
    MAX ( 'Table'[Status] ),
    IF (
        COUNTROWS ( FILTER ( 'Table', [Status] = "Approved" ) )
            = COUNTROWS ( 'Table' ),
        "Approved",
        "Review"
    )
)

Final output:

vjianbolimsft_0-1675131187617.png

Best Regards,

Jianbo Li

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

TomMartens
Super User
Super User

Hey @glycine76 ,

 

this measure:

Measure = 
COUNTX(
    VALUES( 'Status'[Lvl1] )
    , var noOfRowsLvl2 = 
        COUNTROWS(
            CALCULATETABLE(
                VALUES( 'Status'[Lvl2] )
                , ALL( 'Status'[Lvl2] )
                , ALL( 'Status'[Status] )
            )
        )
    var noOfRowsApproved = 
        COUNTROWS(
                CALCULATETABLE(
                    FILTER( 
                        'Status'
                        , 'Status'[Status] = "Approved"
                    )
                    , ALL( 'Status'[Lvl2] )
                    , ALL( 'Status'[Status] )
                )
            )
    return
    IF( noOfRowsLvl2 = noOfRowsApproved , 1 , BLANK() )
)

Allows creating this table visual:
image.png

Please be aware that I enabled the option "Show items with no data" on the column Lvl1, this option does not affect the measure, but it helps to understand my sample data, and why Lvl1 = B is not considered "complete".

Hopefully, this provides what you are looking for.

 

Regards,

Tom

Use the table tool when you are providing simple sample data otherwise it will eat up time from people trying to help:
image.png



Did I answer your question? Mark my post as a solution, this will help others!

Proud to be a Super User!
I accept Kudos 😉
Hamburg, Germany

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.