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
Tangi12
Frequent Visitor

Count Rows in Table Based on Value

I have looked through this forum for my specific issue and couldn't find anything. 

 

I have a calculated column that measures the depth of a hierarchy for an individual,  For example, president = 1, VP = 2, Director =3, Manager = 4 and so on. 

 

I have a formula that I determine the minimum hierarchy number in the list. So if none filtered, hierarchy = 1. I want to count the amount of times 1 appears in the table however when I enter the dax formula for count I get the count for the entire table.

 

Here is my formula.

 

For Min value:

.Min Security Level = Calculate(Min(Security[HierarchyDepth]),AllSelected(Security[HierarchyDepth]))

 

For Count:

.Count Hierarchy Depth = Calculate(COUNT(Security[HierarchyDepth]),Filter(Security,Security[HierarchyDepth]=[.Min Security Level]))

 

No matter how I change the count formula, the count comes out the same. It counts the entire table. My initial thought is ".Min Security Level" is being evaluated at each line but I thought that MinX was used for that.  

 

I would greatly appreciate any help.

 

 

1 ACCEPTED SOLUTION
harshnathani
Community Champion
Community Champion

Hi @Tangi12 ,

 

 

Try something like this

 

Count Hierarchy Depth = 

var a = SELECTEDVALUE(Security[HierarchyDepth])
RETURN
Calculate(COUNT(Security[HierarchyDept]),FILTER(Security, Security[HierarchyDepth] = a))

 

Regards,

Harsh Nathani

View solution in original post

2 REPLIES 2
harshnathani
Community Champion
Community Champion

Hi @Tangi12 ,

 

 

Try something like this

 

Count Hierarchy Depth = 

var a = SELECTEDVALUE(Security[HierarchyDepth])
RETURN
Calculate(COUNT(Security[HierarchyDept]),FILTER(Security, Security[HierarchyDepth] = a))

 

Regards,

Harsh Nathani

This worked! Thank you so much. The only thing I changed was "var a".  I used mina with it.  

 

So my final formula was

 

.Count Hierarchy Depth = 

var a = Mina(Security[HierarchyDepth])
RETURN
Calculate(COUNT(Security[HierarchyDepth]),FILTER(Security, Security[HierarchyDepth] = a))

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.

Top Solution Authors