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

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.

Reply
tberr86
Frequent Visitor

Countrows help

Working on a measure that calculates a count of homes based on two conditions: homes still being built and finished but unsold, without duplicates. I'm sure there are a few approaches to this, here is what I came up with:
 
Total WIP = VAR ActiveWIP = COUNTROWS(CALCULATETABLE('SCHEDHOUSEDETAIL','SCHEDHOUSEDETAIL'[activitycode]="Q75",ISBLANK('SCHEDHOUSEDETAIL'[actualfinishdate])))
            VAR UnsoldCompletedHomes = COUNTROWS(CALCULATETABLE('SCHEDHOUSEDETAIL','SCHEDHOUSEDETAIL'[activitycode]="Q75",NOT(ISBLANK('SCHEDHOUSEDETAIL'[actualfinishdate])),ISBLANK(RELATED('HOUSE MASTER'[contract_date])),NOT(ISBLANK(RELATED('HOUSE MASTER'[Start Date])))))
            RETURN ActiveWIP+UnsoldCompletedHomes
 
Hopefully this gives a clear idea of what the function is trying to accomplish. There is a many to one relationship between schedhousedetail and housemaster. I know I'm wrong in the RELATED function, but not sure how to accomplish this.
I appreciate the guidance!
1 ACCEPTED SOLUTION
OwenAuger
Super User
Super User

Hi @tberr86 

 

As you've rightly said, RELATED is not required here. RELATED requires a row context which does not exist in a measure (unless introduced within the measure by an iterator). In any case, filters applied to tables on the 1-side of a 1:many relationship automatically "propogate" from the 1-side to the many-side table.

 

I would also suggest CALCULATE ( COUNTROWS (...) ) rather than COUNTROWS ( CALCULATETABLE (...) )

 

Also, since the "Q75" filter is common to both components of the measure, you could use an outer CALCULATE with that filter applied, and place the remaining filters within nested CALCULATE calls.

 

Putting all this together, you could write something like this:

Total WIP =
CALCULATE (
    VAR ActiveWIP =
        CALCULATE (
            COUNTROWS ( 'SCHEDHOUSEDETAIL' ),
            ISBLANK ( 'SCHEDHOUSEDETAIL'[actualfinishdate] )
        )
    VAR UnsoldCompletedHomes =
        CALCULATE (
            COUNTROWS ( 'SCHEDHOUSEDETAIL' ),
            NOT ISBLANK ( 'SCHEDHOUSEDETAIL'[actualfinishdate] ),
            ISBLANK ( 'HOUSE MASTER'[contract_date] ),
            NOT ISBLANK ( 'HOUSE MASTER'[Start Date] )
        )
    RETURN
        ActiveWIP + UnsoldCompletedHomes,
    'SCHEDHOUSEDETAIL'[activitycode] = "Q75"
)

 

Alternatively, you could create two separate measures for ActiveWIP and UnsoldCompleteHomes, and sum them in the Total WIP. 

 

Does the above measure give the expected result?

 

Regards,

Owen


Owen Auger
Did I answer your question? Mark my post as a solution!
Blog
LinkedIn

View solution in original post

2 REPLIES 2
OwenAuger
Super User
Super User

Hi @tberr86 

 

As you've rightly said, RELATED is not required here. RELATED requires a row context which does not exist in a measure (unless introduced within the measure by an iterator). In any case, filters applied to tables on the 1-side of a 1:many relationship automatically "propogate" from the 1-side to the many-side table.

 

I would also suggest CALCULATE ( COUNTROWS (...) ) rather than COUNTROWS ( CALCULATETABLE (...) )

 

Also, since the "Q75" filter is common to both components of the measure, you could use an outer CALCULATE with that filter applied, and place the remaining filters within nested CALCULATE calls.

 

Putting all this together, you could write something like this:

Total WIP =
CALCULATE (
    VAR ActiveWIP =
        CALCULATE (
            COUNTROWS ( 'SCHEDHOUSEDETAIL' ),
            ISBLANK ( 'SCHEDHOUSEDETAIL'[actualfinishdate] )
        )
    VAR UnsoldCompletedHomes =
        CALCULATE (
            COUNTROWS ( 'SCHEDHOUSEDETAIL' ),
            NOT ISBLANK ( 'SCHEDHOUSEDETAIL'[actualfinishdate] ),
            ISBLANK ( 'HOUSE MASTER'[contract_date] ),
            NOT ISBLANK ( 'HOUSE MASTER'[Start Date] )
        )
    RETURN
        ActiveWIP + UnsoldCompletedHomes,
    'SCHEDHOUSEDETAIL'[activitycode] = "Q75"
)

 

Alternatively, you could create two separate measures for ActiveWIP and UnsoldCompleteHomes, and sum them in the Total WIP. 

 

Does the above measure give the expected result?

 

Regards,

Owen


Owen Auger
Did I answer your question? Mark my post as a solution!
Blog
LinkedIn

@OwenAuger ,

 

Thank you! Not just for the solution but for the explaination, really helped clarify how the functions work.

Helpful resources

Announcements
July 2025 community update carousel

Fabric Community Update - July 2025

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

July PBI25 Carousel

Power BI Monthly Update - July 2025

Check out the July 2025 Power BI update to learn about new features.