cancel
Showing results for
Did you mean:

Find everything you need to get certified on Fabric—skills challenges, live sessions, exam prep, role guidance, and more. Get started

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

#### Europe’s largest Microsoft Fabric Community Conference

Join the community in Stockholm for expert Microsoft Fabric learning including a very exciting keynote from Arun Ulag, Corporate Vice President, Azure Data.

#### Power BI Monthly Update - June 2024

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

#### Fabric Community Update - June 2024

Get the latest Fabric updates from Build 2024, key Skills Challenge voucher deadlines, top blogs, forum posts, and product ideas.

Top Solution Authors
Top Kudoed Authors