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

Calling all Data Engineers! Fabric Data Engineer (Exam DP-700) live sessions are back! Starting October 16th. Sign up.

Reply
as1195
Helper I
Helper I

Counting number of occurrences in DAX

Hi,

I am trying to find out total number of occurences of a  Range measure .

I have a column called  offset from the time table & for every offset, based on certain conditions am finding the range .Requirement is to count the number of occurenecs for  each range as shown below in the expected output column.

I am using offset column and range measure in a table visual and am looking to solve this without creating any calculated table as connection method is Live.

as1195_0-1690807554412.png

 

1 ACCEPTED SOLUTION
v-zhangti
Community Support
Community Support

Hi, @as1195 

 

You can try the following methods.

Measure:

Range = SWITCH(TRUE(),
SELECTEDVALUE('Table'[Number])>=151&&SELECTEDVALUE('Table'[Number])<157,"151-157",
SELECTEDVALUE('Table'[Number])>=139&&SELECTEDVALUE('Table'[Number])<145,"139-145",
SELECTEDVALUE('Table'[Number])>=133&&SELECTEDVALUE('Table'[Number])<139,"133-139",
SELECTEDVALUE('Table'[Number])>=127&&SELECTEDVALUE('Table'[Number])<133,"127-133")
Count = 
VAR CurrentRange = [Range]
RETURN
CALCULATE(COUNTROWS('Table'), FILTER(ALL('Table'), [Range] = CurrentRange ))

vzhangti_0-1690944807240.png

Is this the result you expect?

 

Best Regards,

Community Support Team _Charlotte

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-zhangti
Community Support
Community Support

Hi, @as1195 

 

You can try the following methods.

Measure:

Range = SWITCH(TRUE(),
SELECTEDVALUE('Table'[Number])>=151&&SELECTEDVALUE('Table'[Number])<157,"151-157",
SELECTEDVALUE('Table'[Number])>=139&&SELECTEDVALUE('Table'[Number])<145,"139-145",
SELECTEDVALUE('Table'[Number])>=133&&SELECTEDVALUE('Table'[Number])<139,"133-139",
SELECTEDVALUE('Table'[Number])>=127&&SELECTEDVALUE('Table'[Number])<133,"127-133")
Count = 
VAR CurrentRange = [Range]
RETURN
CALCULATE(COUNTROWS('Table'), FILTER(ALL('Table'), [Range] = CurrentRange ))

vzhangti_0-1690944807240.png

Is this the result you expect?

 

Best Regards,

Community Support Team _Charlotte

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

 

eliasayyy
Memorable Member
Memorable Member

Please try

 

Occursnces = CALCULATE(COUNT('Table'[column]),allexcept('Table','Table'[Range]))

Hi,
Thanks for the reply!
But I dont think this will work as Allexcept only takes table and column as arguments wherin in my case "Range" is calculated measure and not a column

ok can you please provide a sample dataset taht isnt confidential as well as your measures

Helpful resources

Announcements
FabCon Global Hackathon Carousel

FabCon Global Hackathon

Join the Fabric FabCon Global Hackathon—running virtually through Nov 3. Open to all skill levels. $10,000 in prizes!

September Power BI Update Carousel

Power BI Monthly Update - September 2025

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

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.