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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
DataSkills
Resolver I
Resolver I

DAX Query to calculate companies without head office

Hi, 

 

I am attempting to calculate how many companies have no head office. 

COMPANY table

CompanyIDCompanyName
1Acme
2Enterprise
3Joes business
4PowerCleaners

 

BRANCH table

CompanyIDBranchTypeBranchCity
1BranchLondon
1Head OfficeLeeds
1BranchManchester
2BranchHull
3BranchManchester
3BranchLondon
4Head OfficeBristol
4BranchBristol
4BranchLeeds

 

The answer I am expecting for the above scenario would be 2. Enterprise only has a branch and Joes business only has branches. The other 2 companies both have head offices. 

 

I've been using DAX Studio and so far, what I have is:
DEFINE
    VAR HO =
        SELECTCOLUMNS (
            CALCULATETABLE ( Branch, Branch[BranchType] = "Head Office" ),
            "CompanyID", Branch[CompanyId],
            "HOValue", Branch[BranchType]
        )
    VAR BRA =
        SELECTCOLUMNS (
            CALCULATETABLE ( Branch, Branch[BranchType] = "Branch" ),
            "CompanyID", Branch[CompanyId],
            "BranchValue", Branch[BranchType]
        )
   
    VAR COMBO =
        SELECTCOLUMNS(DISTINCT ( FILTER ( NATURALLEFTOUTERJOIN ( BRA, HO ), ISBLANK ( [HOValue] ) ) ), [HOValue])


EVALUATE
COMBO

This gives me a perfect 2 line table with the blank HOValues (which is just want I expect). However, when I attempt to do any kind of countrows or count or anything like that to try to get the number 2 back, it fails. I am stuck! Any suggestions? 

1 ACCEPTED SOLUTION
tamerj1
Super User
Super User

HI @DataSkills 
If you're looking for a measure, please try

Branches Only Companies =
COUNTROWS (
    FILTER (
        VALUES ( Branch[CompanyId] ),
        ISEMPTY (
            FILTER ( CALCULATETABLE ( Branch ), Branch[BranchType] = "Head Office" )
        )
    )
)

View solution in original post

4 REPLIES 4
tamerj1
Super User
Super User

HI @DataSkills 
If you're looking for a measure, please try

Branches Only Companies =
COUNTROWS (
    FILTER (
        VALUES ( Branch[CompanyId] ),
        ISEMPTY (
            FILTER ( CALCULATETABLE ( Branch ), Branch[BranchType] = "Head Office" )
        )
    )
)
ThxAlot
Super User
Super User

Simple enough

ThxAlot_0-1690656289683.png

 

Company Without Headoffice = 
FILTER( COMP, CALCULATE( ISEMPTY( BR ), BR[BranchType] = "Head Office" ) )

ThxAlot_1-1690656342762.png

 



Expertise = List.Accumulate(


        {Days as from Today},


        {Skills and Knowledge},


        (Current, Everyday) => Current & Day.LearnAndPractise(Everyday)


)



OwenAuger
Super User
Super User

Hi @DataSkills 

DAX Studio can only execute DAX queries, which must return a table.

 

So if you change the end of the query to

 

EVALUATE COUNTROWS ( COMBO )

 

you'll receive an error because COUNTROWS ( COMBO ) is a scalar expression.

 

Instead, you can return a 1x1 table containing the scalar value, e.g.

 

EVALUATE
{ COUNTROWS ( COMBO ) }

 

or

 

EVALUATE
ROW ( "Company Count", COUNTROWS ( COMBO ) )

 

On the other hand, if you want to create a measure returning the same value, the measure must return a scalar value and you could reuse the above code (adjusted slightly) with the final step returning COUNTROWS ( COMBO ).

 

Regards


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

@OwenAuger thank you for this response. That makes sense now. You have taught me an important distinction between Dax Studio and Power BI's measure interface!

Helpful resources

Announcements
November Power BI Update Carousel

Power BI Monthly Update - November 2025

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

Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.