Skip to main content
cancel
Showing results for 
Search instead 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

Reply
parry2k
Super User
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
Vvelarde
Community Champion
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

View solution in original post

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

View solution in original post

8 REPLIES 8
parry2k
Super User
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.

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

@parry2k

 

I created a small sample file (which is attached)

Hope it is useful

 

countbymeasure.png

 

 

 

 

 


Regards
Zubair

Please try my custom visuals

Hi @Zubair_Muhammad

 

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.

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

Vvelarde
Community Champion
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

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

@parry2k@Vvelarde

 

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

parry2k.png

 

 


Regards
Zubair

Please try my custom visuals

Helpful resources

Announcements
Sept PBI Carousel

Power BI Monthly Update - September 2024

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

September Hackathon Carousel

Microsoft Fabric & AI Learning Hackathon

Learn from experts, get hands-on experience, and win awesome prizes.

Sept NL Carousel

Fabric Community Update - September 2024

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