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

Score big with last-minute savings on the final tickets to FabCon Vienna. Secure your discount

Reply
Anonymous
Not applicable

DAX Span of control

I have a table that looks like this

 

H1H2H3H4H5Span of control
John    2
JohnAndrew   1
JohnAndrewMary  2
JohnAndrewMaryJames 2
JohnAndrewMaryJamesJosh0
JohnAndrewMaryJamesHeather0
JohnAndrewMaryJustin 2
JohnAndrewMaryJustinJanet0
JohnAndrewMaryJustinMichelle0
JohnMarkAdam  1
JohnMarkAdamPeter 0
JohnMarkAngela  1
JohnMarkAngelaAndrea 0

 

I need a measure that gives me that span of control in the last column. It basically gives me how many people directly report to the person on the very right. So first row refers to John, and John has Andrew and Mark reporting to them, so 2. Second row refers to Andrew, who has only Mary reporting to him, so 1. And so goes.

 

Thanks

13 REPLIES 13
Greg_Deckler
Community Champion
Community Champion

@Anonymous - Is it OK to unpivot your columns and remove the blanks and then work with that data model? I think it would be easier to achieve the things you are trying to do maybe.



Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
DAX For Humans

DAX is easy, CALCULATE makes DAX hard...
Anonymous
Not applicable

@Greg_Deckler No, because that's what the database looks like 😞 

Do you want the solution in Power Query or in DAX?  Why would you need a measure - I don't see how the result could be impacted by filters?

Anonymous
Not applicable

@lbendlin 

DAX

I won't be using any filters I just need that raw table

Let me rephrase.  Do you need a measure or can it be a calculated column?

Anonymous
Not applicable

@lbendlin measure

 

SOC := 
var h1 = SELECTEDVALUE(SoC[H1])
var h2 = SELECTEDVALUE(SoC[H2])
var h3 = SELECTEDVALUE(SoC[H3])
var h4 = SELECTEDVALUE(SoC[H4])
var h5 = SELECTEDVALUE(SoC[H5])
return switch(TRUE()
,h2="",CALCULATE(DISTINCTCOUNT(SoC[H2])-1,ALL(SoC),SoC[H1]=h1)
,h3="",CALCULATE(DISTINCTCOUNT(SoC[H3])-1,ALL(SoC),SoC[H2]=h2)
,h4="",CALCULATE(DISTINCTCOUNT(SoC[H4])-1,ALL(SoC),SoC[H3]=h3)
,h5="",CALCULATE(DISTINCTCOUNT(SoC[H5])-1,ALL(SoC),SoC[H4]=h4)
,0)

 

Note that your sample data is missing the "John -> Mark"  row.

 

Anonymous
Not applicable

@lbendlin 

SOC := 
var h1 = SELECTEDVALUE(SoC[H1])
var h2 = SELECTEDVALUE(SoC[H2])
var h3 = SELECTEDVALUE(SoC[H3])
var h4 = SELECTEDVALUE(SoC[H4])
var h5 = SELECTEDVALUE(SoC[H5])
return switch(TRUE()
,h2="",CALCULATE(DISTINCTCOUNT(SoC[H2])-1,ALL(SoC),SoC[H1]=h1)
,h3="",CALCULATE(DISTINCTCOUNT(SoC[H3])-1,ALL(SoC),SoC[H2]=h2)
,h4="",CALCULATE(DISTINCTCOUNT(SoC[H4])-1,ALL(SoC),SoC[H3]=h3)
,h5="",CALCULATE(DISTINCTCOUNT(SoC[H5])-1,ALL(SoC),SoC[H4]=h4)
,0)

 

That gave me -1 for all rows

Is your main table's name "SoC"  ?  If not then you need to adjust the measure accordingly.

Anonymous
Not applicable

@lbendlin Yes I adjusted

Here's an alternative version:

 

SOC := 
switch(TRUE()
,max(SoC[H5])>"",0
,max(SoC[H4])>"",CALCULATE(DISTINCTCOUNT(SoC[H5]),REMOVEFILTERS(SoC[H5]))-1
,max(SoC[H3])>"",CALCULATE(DISTINCTCOUNT(SoC[H4]),REMOVEFILTERS(SoC[H4]))-1
,max(SoC[H2])>"",CALCULATE(DISTINCTCOUNT(SoC[H3]),REMOVEFILTERS(SoC[H3]))-1
,CALCULATE(DISTINCTCOUNT(SoC[H2]),REMOVEFILTERS(SoC[H2]))-1
)
Anonymous
Not applicable

@lbendlin That still gives me -1 for all rows...

That's most likely because you have a more involved data model.  It works fine for a standalone table based on your sample data.

Helpful resources

Announcements
August Power BI Update Carousel

Power BI Monthly Update - August 2025

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

August 2025 community update carousel

Fabric Community Update - August 2025

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