Forum Discussion

markmsc's avatar
markmsc
Resolver I
10 months ago
Solved

Matrix column based on other matrix columns

Hello colleagues -- I have some data that I need to turn into a matrix in one or more steps, but I'm a bit unclear on how to build up to the final result.  Let's say this is my dataset:   City ...
  • Irwan's avatar
    Irwan
    10 months ago

    hello markmsc 

     

    please check if this accomodate your need.

    create a couple measures for apple, pear, elm, oak, and birch.

    Apple =
    SUMX(
        FILTER(
            'Table',
            'Table'[Fruit]="Apple"
        ),
        'Table'[Num1]
    )
    Pear =
    SUMX(
        FILTER(
            'Table',
            'Table'[Fruit]="Pear"
        ),
        'Table'[Num1]
    )
    Elm =
    var _Elm =
    SUMX(
        FILTER(
            'Table',
            'Table'[Tree]="Elm"
        ),
        'Table'[Num2]
    )
    Return
    DIVIDE(
        _Elm,
        [Apple]+[Pear]
    )
    Oak =
    var _Oak =
    SUMX(
        FILTER(
            'Table',
            'Table'[Tree]="Oak"
        ),
        'Table'[Num2]
    )
    var _Melon =
    SUMX(
        FILTER(
            'Table',
            'Table'[Fruit]="Melon"
        ),
        'Table'[Num1]
    )
    Return
    DIVIDE(
        _Oak,
        _Melon
    )
    Birch =
    var _Birch =
    SUMX(
        FILTER(
            'Table',
            'Table'[Tree]="Birch"
        ),
        'Table'[Num2]
    )
    Return
    DIVIDE(
        _Birch,
        [Apple]+[Pear]
    )
     
    Hope this will help.
    Thank you.
  • Jihwan_Kim's avatar
    10 months ago

    Hi,

    Please check the below picture and the attached pbix file.

    I tried to implement calculation group.

     

     

     

     

     

  • Ahmedx's avatar
    10 months ago

    Another variant
    1) I created the DimFruitTree table in Power Query
    3) you need to sort the FruitTree column by Index

    2) The relationship is like this

  • Kedar_Pande's avatar
    10 months ago

    markmsc 

    For Fruit columns (Apple/Pear/Melon):

    Fruit Measure = SUM(Data[Num1])

     

    For Tree columns (Elm/Oak/Birch):

    Tree Measure =
    VAR AppleSum = CALCULATE([Fruit Measure], 'Data'[Fruit] = "Apple")
    VAR PearSum = CALCULATE([Fruit Measure], 'Data'[Fruit] = "Pear")
    VAR MelonSum = CALCULATE([Fruit Measure], 'Data'[Fruit] = "Melon")
    RETURN
    SWITCH(
    SELECTEDVALUE('Data'[Tree]),
    "Elm", DIVIDE(SUM(Data[Num2]), AppleSum + PearSum),
    "Oak", DIVIDE(SUM(Data[Num2]), MelonSum),
    "Birch", DIVIDE(SUM(Data[Num2]), AppleSum + PearSum)
    )

     

    Use these measures in your matrix with City as rows, and Fruit/Tree as columns.