cancel
Showing results 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.

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

Community Champion

@parry2k

I created a small sample file (which is attached)

Hope it is useful

Regards
Zubair

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

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

Announcements

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

#### Power BI Monthly Update - April 2024

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

#### Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.

Top Solution Authors
Top Kudoed Authors