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
Maheshwari
New Member

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

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
New Member

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

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