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

Earn a 50% discount on the DP-600 certification exam by completing the Fabric 30 Days to Learn It challenge.

Super User

## count by measure

hi there,

I have  a calculated measure to calculate the share % of each category, based on category share there is ranking, if % > 20 then A if % > 10 then B else C

I added the measure for ranking as well, so in table category, %  and rank all looks good.

I want to count number of categories under each rank. What is the best way to achieve it?

thanks,

P

Subscribe to the @PowerBIHowTo YT channel for an upcoming video on List and Record functions in Power Query!!

Learn Power BI and Fabric - subscribe to our YT channel - Click here: @PowerBIHowTo

If my solution proved useful, I'd be delighted to receive Kudos. When you put effort into asking a question, it's equally thoughtful to acknowledge and give Kudos to the individual who helped you solve the problem. It's a small gesture that shows appreciation and encouragement! ❤

Did I answer your question? Mark my post as a solution. Proud to be a Super User! Appreciate your Kudos 🙂
Feel free to email me with any of your BI needs.

2 ACCEPTED SOLUTIONS
Community Champion

@parry2k

Try with this modification:

```RANK =
VAR Share = [% share]
RETURN
IF ( Share > 0.10, "A", IF ( Share > 0.05, "B", "C" ) )```

Victor

Lima - Peru
Super User

@VvelardeThanks for getting back. Although I sorted it out but wanted to check how you experts will do. I will test your solution. Cheers!!

Subscribe to the @PowerBIHowTo YT channel for an upcoming video on List and Record functions in Power Query!!

Learn Power BI and Fabric - subscribe to our YT channel - Click here: @PowerBIHowTo

If my solution proved useful, I'd be delighted to receive Kudos. When you put effort into asking a question, it's equally thoughtful to acknowledge and give Kudos to the individual who helped you solve the problem. It's a small gesture that shows appreciation and encouragement! ❤

Did I answer your question? Mark my post as a solution. Proud to be a Super User! Appreciate your Kudos 🙂
Feel free to email me with any of your BI needs.

8 REPLIES 8
Super User

Just to add more there will be slicer on category so the solution should work if any value is selected in a slicer.

Subscribe to the @PowerBIHowTo YT channel for an upcoming video on List and Record functions in Power Query!!

Learn Power BI and Fabric - subscribe to our YT channel - Click here: @PowerBIHowTo

If my solution proved useful, I'd be delighted to receive Kudos. When you put effort into asking a question, it's equally thoughtful to acknowledge and give Kudos to the individual who helped you solve the problem. It's a small gesture that shows appreciation and encouragement! ❤

Did I answer your question? Mark my post as a solution. Proud to be a Super User! Appreciate your Kudos 🙂
Feel free to email me with any of your BI needs.

Community Champion

HI @parry2k

Try this approach

Create a calculated table of all available RANKS (a,b,c,d etc)

`RANKs = DATATABLE("RANK",STRING,{{"A"},{"B"}})`

Then you can use this MEASURE to count categories against each RANK

```Measure =
COUNTX (
FILTER (
ALLSELECTED ( Table1[Category] ),
[RANK] = SELECTEDVALUE ( RANKs[RANK] )
),
1
)```

Regards
Zubair

Please try my custom visuals
Community Champion

@parry2k

I created a small sample file (which is attached)

Hope it is useful

Regards
Zubair

Please try my custom visuals
Super User

I was doing the same but here are few changes which I made and it is not working:

- No sum on amount in table to calculate %

- % is calculated based on allselected

- small change in rank formula to get 3 values

- made changes to "measure" to allselected instead of allselected(Table1[Category])

now if you select multiple values in slicer, you don't get correct result. Take a look, I made the changes in attached.

Thanks,

P

Subscribe to the @PowerBIHowTo YT channel for an upcoming video on List and Record functions in Power Query!!

Learn Power BI and Fabric - subscribe to our YT channel - Click here: @PowerBIHowTo

If my solution proved useful, I'd be delighted to receive Kudos. When you put effort into asking a question, it's equally thoughtful to acknowledge and give Kudos to the individual who helped you solve the problem. It's a small gesture that shows appreciation and encouragement! ❤

Did I answer your question? Mark my post as a solution. Proud to be a Super User! Appreciate your Kudos 🙂
Feel free to email me with any of your BI needs.

Super User

@Phil_Seamark @Vvelarde @MFelix @Anonymous

Hello datanuts, any feedback on this post?

Thanks,

P

Subscribe to the @PowerBIHowTo YT channel for an upcoming video on List and Record functions in Power Query!!

Learn Power BI and Fabric - subscribe to our YT channel - Click here: @PowerBIHowTo

If my solution proved useful, I'd be delighted to receive Kudos. When you put effort into asking a question, it's equally thoughtful to acknowledge and give Kudos to the individual who helped you solve the problem. It's a small gesture that shows appreciation and encouragement! ❤

Did I answer your question? Mark my post as a solution. Proud to be a Super User! Appreciate your Kudos 🙂
Feel free to email me with any of your BI needs.

Community Champion

@parry2k

Try with this modification:

```RANK =
VAR Share = [% share]
RETURN
IF ( Share > 0.10, "A", IF ( Share > 0.05, "B", "C" ) )```

Victor

Lima - Peru
Super User

@VvelardeThanks for getting back. Although I sorted it out but wanted to check how you experts will do. I will test your solution. Cheers!!

Subscribe to the @PowerBIHowTo YT channel for an upcoming video on List and Record functions in Power Query!!

Learn Power BI and Fabric - subscribe to our YT channel - Click here: @PowerBIHowTo

If my solution proved useful, I'd be delighted to receive Kudos. When you put effort into asking a question, it's equally thoughtful to acknowledge and give Kudos to the individual who helped you solve the problem. It's a small gesture that shows appreciation and encouragement! ❤

Did I answer your question? Mark my post as a solution. Proud to be a Super User! Appreciate your Kudos 🙂
Feel free to email me with any of your BI needs.

Community Champion

Sorry I couldn't get time to look into this after my intial post.

Victor is right ..Great observation....this modification should fix the matter for Count of Categories

"The measure "RANK" inside FILTER (or any other ITERATOR function) will modify itself according to the Table passed as argument inside the ITERATOR. Thats why it should be put in a variable first"

Attached revised file as well

To get the distinctcount of categories

```DistinctCount_Categories =
VAR myrank =
SELECTEDVALUE ( RANKs[RANK] )
RETURN
CALCULATE (
DISTINCTCOUNT ( Table1[Category] ),
CALCULATETABLE (
VALUES ( Table1[Category] ),
FILTER ( Table1, [Rank] = myrank )
)
)```

Regards
Zubair

Please try my custom visuals

## Helpful resources

Announcements

#### New forum boards available in Real-Time Intelligence.

Ask questions in Eventhouse and KQL, Eventstream, and Reflex.

#### Power BI Monthly Update - May 2024

Check out the May 2024 Power BI update to learn about new features.

#### Fabric certifications survey

Certification feedback opportunity for the community.

Top Solution Authors
Top Kudoed Authors