Forum Discussion

memasarif's avatar
memasarif
New Member
5 years ago
Solved

Divide each row by categories in a table

Dear All,

I would like to have a measure column that divide rows of sales with channel X and Y for each date. How can I do that please help?

Date               Channel     Sales
12/01/20            X             20
12/01/20            Y             10
03/05/20            X             200
03/05/20            Y              50

The desired  outcome with desired measure ratio column will be below
Date                  Ratio
12/01/20           20/10=2
03/05/20           200/50=4

Thank you

  • Please try a measure expression like this

     

    XY Ratio =
    VAR vX =
        CALCULATE (
            SUM ( Table[Sales] ),
            Table[Category] = "X"
        )
    VAR vY =
        CALCULATE (
            SUM ( Table[Sales] ),
            Table[Category] = "Y"
        )
    RETURN
        DIVIDE (
            vX,
            vY
        )

     

    Pat

5 Replies

  • mahoneypat's avatar
    mahoneypat
    Icon for Microsoft Employee rankMicrosoft Employee

    Please try a measure expression like this

     

    XY Ratio =
    VAR vX =
        CALCULATE (
            SUM ( Table[Sales] ),
            Table[Category] = "X"
        )
    VAR vY =
        CALCULATE (
            SUM ( Table[Sales] ),
            Table[Category] = "Y"
        )
    RETURN
        DIVIDE (
            vX,
            vY
        )

     

    Pat

  • Reshape the data in power query so you have one row per date and a column for x then y. 

    Did I answer your question? Mark my post as a solution if I did! Like it if it helped.  Appreciate the Kudos!!

     

    load into power bi and create measure to 


    Divide measure: 

    Var _x = sum(tableName[x])

    Var _y = sum(tableNmae[y]
    RETURN

     

    Divide(_x, _y)