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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
jppasini
New Member

How to divide two different rows in a table

Hello everybody!

I´m bogged, trying to solve a simple problem. I have a "Sales" table with info such as this:

OrderSKUQuantity
1

Banana

10
1

Apple

5
2Banana10
2Apple1
3Banana10
3Apple5
4Banana10
5Apple2

 

I need to generate a grand total for Bananas, a grand total for Apples, and then divide Apples/Banannas.

In this example:

GT Bananas = 40

GT Apples = 13

Ratio = 13 / 40 = 32,5%

 

I use this method to compare the sales of a "weak" product (apples) vs the sales of a "strong" product (bananas) and to find new opportunities to cross-sell.

 

Any helping hand/brain?

1 ACCEPTED SOLUTION
CoreyP
Solution Sage
Solution Sage

Measure 1:

GT Apples = CALCULATE( SUM( 'Sales'[Quantity] ) , 'Sales'[SKU] = "Apples" )

 

Measure 2:

GT Bananas = CALCULATE( SUM( 'Sales'[Quantity] ) , 'Sales'[SKU] = "Bananas" )

 

Measure 3:

Apple % of Banana = [GT Apples] / [GT Bananas]

 

Or, you could combine into one measure like this:

 

Apple % of Banana = 

VAR 

GT_Apples = CALCULATE( SUM( 'Sales'[Quantity] ) , 'Sales'[SKU] = "Apples" )

GT_Bananas = CALCULATE( SUM( 'Sales'[Quantity] ) , 'Sales'[SKU] = "Bananas" )

 

RETURN

GT_Apples / GT_Bananas

View solution in original post

3 REPLIES 3
v-juanli-msft
Community Support
Community Support

Hi @jppasini 

Create measures

total per sku = CALCULATE(SUM('Table'[Quantity]),ALLEXCEPT('Table','Table'[SKU]))

weak/strong =
VAR min_ =
    MINX ( ALL ( 'Table'[SKU] ), [total per sku] )
VAR max_ =
    MAXX ( ALL ( 'Table'[SKU] ), [total per sku] )
RETURN
    SWITCH ( [total per sku], min_, "weak", max_, "strong" )

ratio =
CALCULATE (
    [total per sku],
    FILTER ( ALLSELECTED ( 'Table' ), [weak/strong] = "weak" )
)
    / CALCULATE (
        [total per sku],
        FILTER ( ALLSELECTED ( 'Table' ), [weak/strong] = "strong" )
    )

Capture6.JPG

Best Regards
Maggie
Community Support Team _ Maggie Li
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

CoreyP
Solution Sage
Solution Sage

Measure 1:

GT Apples = CALCULATE( SUM( 'Sales'[Quantity] ) , 'Sales'[SKU] = "Apples" )

 

Measure 2:

GT Bananas = CALCULATE( SUM( 'Sales'[Quantity] ) , 'Sales'[SKU] = "Bananas" )

 

Measure 3:

Apple % of Banana = [GT Apples] / [GT Bananas]

 

Or, you could combine into one measure like this:

 

Apple % of Banana = 

VAR 

GT_Apples = CALCULATE( SUM( 'Sales'[Quantity] ) , 'Sales'[SKU] = "Apples" )

GT_Bananas = CALCULATE( SUM( 'Sales'[Quantity] ) , 'Sales'[SKU] = "Bananas" )

 

RETURN

GT_Apples / GT_Bananas

az38
Community Champion
Community Champion

hi @jppasini 

try a measure

Measure = divide(calculate(sum('Table1'[Quantity]);ALL('Table1');'Table1'[SKU]="Banana");calculate(sum('Table1'[Quantity]);ALL('Table1');'Table1'[SKU]="Apple"))

do not hesitate to give a kudo to useful posts and mark solutions as solution

LinkedIn


do not hesitate to give a kudo to useful posts and mark solutions as solution
LinkedIn

Helpful resources

Announcements
November Power BI Update Carousel

Power BI Monthly Update - November 2025

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

Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.

Top Kudoed Authors