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
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
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.