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

Don't miss out! 2025 Microsoft Fabric Community Conference, March 31 - April 2, Las Vegas, Nevada. Use code MSCUST for a $150 discount. Prices go up February 11th. Register now.

Reply
absis
New Member

Divide by row in Power BI


Hi guys,

I've been having a little problem doing something in the matrix.

 

I have the following table

Product            Price         Quantity

AA                   1000           50

BB                    2000          40

CC                   3000           30
DD                  4000           20

 

I need to divide by row and also add more new row like Ratio_CCDD, CC/DD get a result for a row of CC divided by a row of DD product.

The result in Maxtrix should follow:


Product                  Price          Quantity            Amount

AA                         1000            50                      50000

BB                          2000            40                      80000

CC                         3000            30                       90000
Ratio_CCDD          0.75             1.5                      1.125

DD                        4000             20                      80000

 

How can I solve this?

 

Cheers!

1 ACCEPTED SOLUTION
v-eachen-msft
Community Support
Community Support

Hi @absis ,

 

At first, you need a calculated column “Amount”.

Amount =
'Table'[Price] * 'Table'[Quantity]

According to the description of your problem, I divide CC by DD. The result will appear in a new table “Table 2”.

Table 2 =
ROW (
    "Product", "Ratio_"
        & CALCULATE (
            SELECTEDVALUE ( 'Table'[Product] ),
            FILTER ( 'Table', 'Table'[Product] = "CC" )
        )
        & CALCULATE (
            SELECTEDVALUE ( 'Table'[Product] ),
            FILTER ( 'Table', 'Table'[Product] = "DD" )
        ),
    "Price", DIVIDE (
        CALCULATE (
            SELECTEDVALUE ( 'Table'[Price] ),
            FILTER ( 'Table', 'Table'[Product] = "CC" )
        ),
        CALCULATE (
            SELECTEDVALUE ( 'Table'[Price] ),
            FILTER ( 'Table', 'Table'[Product] = "DD" )
        )
    ),
    "Quantity", DIVIDE (
        CALCULATE (
            SELECTEDVALUE ( 'Table'[Quantity] ),
            FILTER ( 'Table', 'Table'[Product] = "CC" )
        ),
        CALCULATE (
            SELECTEDVALUE ( 'Table'[Quantity] ),
            FILTER ( 'Table', 'Table'[Product] = "DD" )
        )
    ),
    "Amount", DIVIDE (
        CALCULATE (
            SELECTEDVALUE ( 'Table'[Amount] ),
            FILTER ( 'Table', 'Table'[Product] = "CC" )
        ),
        CALCULATE (
            SELECTEDVALUE ( 'Table'[Amount] ),
            FILTER ( 'Table', 'Table'[Product] = "DD" )
        )
    )
)

Then use UNION() function to combine two tables into one table “Table 3”.

 

Table 3 =
UNION ( 'Table', 'Table 2' )

3-1.PNG

Best Regards,

Eads

 

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

 

Community Support Team _ Eads
If this post helps, then please consider Accept it as the solution to help the other members find it.

View solution in original post

1 REPLY 1
v-eachen-msft
Community Support
Community Support

Hi @absis ,

 

At first, you need a calculated column “Amount”.

Amount =
'Table'[Price] * 'Table'[Quantity]

According to the description of your problem, I divide CC by DD. The result will appear in a new table “Table 2”.

Table 2 =
ROW (
    "Product", "Ratio_"
        & CALCULATE (
            SELECTEDVALUE ( 'Table'[Product] ),
            FILTER ( 'Table', 'Table'[Product] = "CC" )
        )
        & CALCULATE (
            SELECTEDVALUE ( 'Table'[Product] ),
            FILTER ( 'Table', 'Table'[Product] = "DD" )
        ),
    "Price", DIVIDE (
        CALCULATE (
            SELECTEDVALUE ( 'Table'[Price] ),
            FILTER ( 'Table', 'Table'[Product] = "CC" )
        ),
        CALCULATE (
            SELECTEDVALUE ( 'Table'[Price] ),
            FILTER ( 'Table', 'Table'[Product] = "DD" )
        )
    ),
    "Quantity", DIVIDE (
        CALCULATE (
            SELECTEDVALUE ( 'Table'[Quantity] ),
            FILTER ( 'Table', 'Table'[Product] = "CC" )
        ),
        CALCULATE (
            SELECTEDVALUE ( 'Table'[Quantity] ),
            FILTER ( 'Table', 'Table'[Product] = "DD" )
        )
    ),
    "Amount", DIVIDE (
        CALCULATE (
            SELECTEDVALUE ( 'Table'[Amount] ),
            FILTER ( 'Table', 'Table'[Product] = "CC" )
        ),
        CALCULATE (
            SELECTEDVALUE ( 'Table'[Amount] ),
            FILTER ( 'Table', 'Table'[Product] = "DD" )
        )
    )
)

Then use UNION() function to combine two tables into one table “Table 3”.

 

Table 3 =
UNION ( 'Table', 'Table 2' )

3-1.PNG

Best Regards,

Eads

 

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

 

Community Support Team _ Eads
If this post helps, then please consider Accept it as the solution to help the other members find it.

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

Jan25PBI_Carousel

Power BI Monthly Update - January 2025

Check out the January 2025 Power BI update to learn about new features in Reporting, Modeling, and Data Connectivity.

December 2024

A Year in Review - December 2024

Find out what content was popular in the Fabric community during 2024.