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

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

Reply
Maheshwari
Regular Visitor

count the occurrence of values in a column for a dynamically changing value range

Example :If  I have values from 1to 100 like 1,1,5,8,3,3,7,8,1,2... in column. Need to count the occurence of values from 1 to 5, 5 to 10 and so on.(Say here...1 to 5 --> 8 (1,1,5,8,3,31,2), 5 to 10 -->3 (8,7,8)).How to set dynaimc variable using DAX or this could be done in powerquery?

2 ACCEPTED SOLUTIONS
Ashish_Mathur
Super User
Super User

Hi,

The answer should be 7 and 3 (not 8 and 3).  You may download my PBI file from here.

Hope this helps.

Untitled.png


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/

View solution in original post

Anonymous
Not applicable

Hi @Maheshwari 

You can try my way as well. Add a Type column by conditional column in Power query editor and then show results in table visual by count function.

1.png

Click close&apply. Then build a table visual by Type column and count of value column.

2.png

You can download the pbix file from this link: File.pbix

 

Best Regards,

Rico Zhou

 

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

5 REPLIES 5
Maheshwari
Regular Visitor

Thanks Everyone.... I tried the first one & will try remaining two... inbetween I tried static segmentation which works good for my need

Anonymous
Not applicable

Hi @Maheshwari 

You can try my way as well. Add a Type column by conditional column in Power query editor and then show results in table visual by count function.

1.png

Click close&apply. Then build a table visual by Type column and count of value column.

2.png

You can download the pbix file from this link: File.pbix

 

Best Regards,

Rico Zhou

 

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

mahoneypat
Microsoft Employee
Microsoft Employee

This would be a good use of the group/bin feature in Power BI.

Use grouping and binning in Power BI Desktop - Power BI | Microsoft Docs

 

Regards,

Pat





Did I answer your question? Mark my post as a solution! Kudos are also appreciated!

To learn more about Power BI, follow me on Twitter or subscribe on YouTube.


@mahoneypa HoosierBI on YouTube


CNENFRNL
Community Champion
Community Champion

@Maheshwari , the easiest solution lie in Excel, our oldie but goodie; FREQUENCY() is kinda of ready-to-eat for such a question.

 

Here's my verbose solution in PQ; I made the span variable.

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("TY67EcAgDEN3oU4R/AEzi4/91wjnR5EGnfUs4czWre0nm3qJS8nE7Jij3mV/NDE9YIv9DtOSYApK9GWTnN3OaxIYBIQbBBYwY3J+FzplUo2cU/YH", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Value = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Value", Int64.Type}}),

    ds = List.Buffer(List.Sort(#"Changed Type"[Value], Order.Ascending)),
    span = 5,
    Grouped = List.Accumulate(
        ds,
        {{0, 0}},// {{upper boudary, counter}, {}, {}, ...}
        (s,c) => if c>s{0}{0} then {{Number.RoundUp(c/span)*span, s{0}{1}+1}} & List.RemoveFirstN(s) & {{c}} else List.RemoveLastN(s) & {s{s{0}{1}} & {c}}
    ),
    Expanded = Table.FromRecords(List.Transform(List.RemoveFirstN(Grouped), each [Lower Boundary=#"Upper Boundary"-span, Upper Boundary=Number.RoundUp(List.Max(_)/span)*span, Count=List.Count(_)]))
in
    Expanded

 Screenshot 2020-11-28 172547.pngScreenshot 2020-11-28 172742.png


Thanks to the great efforts by MS engineers to simplify syntax of DAX! Most beginners are SUCCESSFULLY MISLED to think that they could easily master DAX; but it turns out that the intricacy of the most frequently used RANKX() is still way beyond their comprehension!

DAX is simple, but NOT EASY!

Ashish_Mathur
Super User
Super User

Hi,

The answer should be 7 and 3 (not 8 and 3).  You may download my PBI file from here.

Hope this helps.

Untitled.png


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/

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!

October Power BI Update Carousel

Power BI Monthly Update - October 2025

Check out the October 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.

Top Solution Authors