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

Power BI is turning 10! Let’s celebrate together with dataviz contests, interactive sessions, and giveaways. Register now.

Reply
pr92
Frequent Visitor

Divide 2 values from same column and separate rows in measure

Hello,

 

I have the following table in my model :

 

Category1Category2Number of tickets
A15FEMALE166960
A15MALE188816
A15Total654229
A15UNKNOWN26456
A6FEMALE226964
A6MALE6242260
A6Total66466
A6UNKNOWN66246
A52FEMALE661456
A52MALE2690604
A52Total486091
A52UNKNOWN441060
A54FEMALE1500896
A54MALE2526514
A54Total456656
A54UNKNOWN512646

 

I need to display the Top Category2 based on the following value : 

 

For each value in Category1 : 

Number of tickets of Category2 /  Number of tickets of Category2 WHERE Category1 = Total

 

 

 

Category1Category2Number of ticketsColonne1
A15FEMALE16696026%
A15MALE18881629%
A15Total654229100%

For example : Here for A15, I need to display MALE (29%)

 

I did the following measure : 

 

%_Tickets_Category1 =

VAR _total = CALCULATE(
    SUM(Table[NumberTickets]),  
    FILTER(
        ALL(Table),  Table[Category2] = "Total")
    )
VAR _sum = SUM(Table[NumberTickets])
RETURN DIVIDE(_sum, _total)
 
On the page I have a segment that filters by Category1
 
It works on the page if I display ALL values in a table but not when I apply filter Top 1 :
 
pr92_0-1727082110519.pngpr92_1-1727082201456.png

 

Any help would  be appreciated

Thank you

1 ACCEPTED SOLUTION
rajendraongole1
Super User
Super User

Hi @pr92 -The measure you've written can be adapted to handle both the division and the correct filtering within the Top N filter context. to calculate the percentage of tickets per Category2 use below one

%_Tickets_Category1 =
VAR _total = CALCULATE(
SUM(Table[Number of tickets]),
FILTER(ALL(Table),
Table[Category2] = "Total" &&
Table[Category1] = SELECTEDVALUE(Table[Category1])
)
)
VAR _sum = SUM(Table[Number of tickets])
RETURN DIVIDE(_sum, _total)

 

Once you have the percentage measure (%_Tickets_Category1), you need to apply the Top N filter to display only the Category2 with the highest percentage for each Category1.

In the Filters pane, click on the Category2 field.Change the filter type to Top N.Enter 1 as the Top N value.
Drag the measure %_Tickets_Category1 into the "By Value" field.
Apply the filter, and Power BI will now display only the top Category2 with the highest percentage for each Category1.

Hope this works 





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!





View solution in original post

1 REPLY 1
rajendraongole1
Super User
Super User

Hi @pr92 -The measure you've written can be adapted to handle both the division and the correct filtering within the Top N filter context. to calculate the percentage of tickets per Category2 use below one

%_Tickets_Category1 =
VAR _total = CALCULATE(
SUM(Table[Number of tickets]),
FILTER(ALL(Table),
Table[Category2] = "Total" &&
Table[Category1] = SELECTEDVALUE(Table[Category1])
)
)
VAR _sum = SUM(Table[Number of tickets])
RETURN DIVIDE(_sum, _total)

 

Once you have the percentage measure (%_Tickets_Category1), you need to apply the Top N filter to display only the Category2 with the highest percentage for each Category1.

In the Filters pane, click on the Category2 field.Change the filter type to Top N.Enter 1 as the Top N value.
Drag the measure %_Tickets_Category1 into the "By Value" field.
Apply the filter, and Power BI will now display only the top Category2 with the highest percentage for each Category1.

Hope this works 





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!





Helpful resources

Announcements
Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

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

June 2025 community update carousel

Fabric Community Update - June 2025

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