Forum Discussion

muhammad_bens's avatar
muhammad_bens
Regular Visitor
2 years ago

Issue with Displaying Correct Values in Matrix Visualization for Grouped Items

Hi Community,

I need help with a matrix visualization in Power BI. My dataset includes items grouped under "Crop" which contains "Area_planted" and "Crop_yield." I want to show a ratio (Area_planted / Crop_yield) for the "Crop" group, but display the actual values for "Area_planted" and "Crop_yield" items.

Here is the measure I’m using for the ratio:

```dax
Crop Ratio =
DIVIDE(
CALCULATE(
SUM('balance_sheet'[Value]),
'balance_sheet'[Items] = "Area_planted"
),
CALCULATE(
SUM('balance_sheet'[Value]),
'balance_sheet'[Items] = "Crop_yield"
),
0
)
And here is the measure to display values in the matrix:
TheTableMeasure =
IF(
SELECTEDVALUE('balance_sheet'[Items (groups)]) = "Crop",
[Crop Ratio],
[Actual Value Measure]
)

However, when I apply this, the "Area_planted" and "Crop_yield" rows show the same ratio value as the "Crop" group, instead of their actual values. How can I display the ratio only for the "Crop" group and the actual values for "Area_planted" and "Crop_yield"?

Thanks for your help!

 




5 Replies

  • aduguid's avatar
    aduguid
    Memorable Member

    Give this a try using INSCOPE

     

    TheTableMeasure =
    	IF (
    		ISINSCOPE ( 'balance_sheet'[Items (groups)] ) && 'balance_sheet'[Items (groups)] = "Crop",
    		[Crop Ratio],
    		[Actual Value Measure]
    	)

     

     

  • Anonymous's avatar
    Anonymous
    Not applicable

    Pls let us know if the carry out group also contains area planted and crop yield data ?

    • muhammad_bens's avatar
      muhammad_bens
      Regular Visitor

      thanks Rakesh for responding , no , carry out do not contains area planted and crop yield 

       

  • Thank you aduguid for replying to my message. I had to make some changes to your code due to a context error, and this is the result:
    Measurement table =
    if (
    ISINSCOPE('Balance'[Articles(Collections)]) && SELECTEDVALUE('Balance'[Articles(Collections)]) = 'Crop',
    [harvest report],
    [Actual value measurement]
    )
    It always shows the same result 😞

  • Anonymous's avatar
    Anonymous
    Not applicable

    Hi muhammad_bens ,

    Whether your problem has been resolved? If no, please update the formula of measure [Measurement table] as below and check if it can return the expected result...

    Measurement table =
    IF (
        ISINSCOPE ( 'Balance'[Articles(Collections)] ),
        IF (
            SELECTEDVALUE ( 'Balance'[Articles(Collections)] ) = 'Crop',
            [harvest report],
            [Actual value measurement]
        )
    )

     

    If the above one can't help you get the expected result, please provide some raw data in your tables(exclude sensitive data) with Text format and your expected result with backend logic and special examples. It would be helpful to find out the solution. You can refer the following link to share the required info:

    How to provide sample data in the Power BI Forum

     

    And It is better if you can share a simplified pbix file. You can refer the following link to upload the file to the community. Thank you.

    How to upload PBI in Community

    Best Regards