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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
Anonymous
Not applicable

How do I SUM and calculate a percentage of specific cells in my matrix?

Hi,

 

I am new to PowerBI and I am trying to SUM the highlighted area in my matrix below. I want to also calculate a percentage based on that SUM divided by the total table (N = 900). Afterward, I would like to create a line chart that demonstrates the percentage over time. However, I am a bit stuck and unsure of how to do that. I have a column in my data source that indicates the time period too.

 

Here is a snapshot of my matrix and the highlighted cells I am trying to calculate:

Screen Shot 2020-04-07 at 4.54.00 PM.png

 

This is the code for the specific highlighted cells:

Screen Shot 2020-04-07 at 4.54.12 PM.png

1 ACCEPTED SOLUTION

I am not asking to the sum of count that. In all you ifs return a sum/count of measure instead of green. In place of other return blank()

View solution in original post

4 REPLIES 4
v-shex-msft
Community Support
Community Support

HI @Anonymous,

I'd like to suggest you create a variable highlight table to store these highlighted fields, then you can use it as conditions to calculate in measure formula:

Measure =
VAR highlighted=
    DATATABLE (
        "Row", STRING,
        "Column", STRING,
        {
            { "5", "2" },
            { "5", "3" },
            { "5", "4" },
            { "5", "5" },
            { "4", "3" },
            { "4", "4" },
            { "4", "5" },
            { "3", "4" },
            { "3", "5" },
            { "2", "5" }
        }
    )
VAR filtered =
    CALCULATETABLE (
        Table,
        ALLSELECTED ( Table ),
        VALUES ( Table[RowField] ),
        VALUES ( Table[ColumnField] )
    )
RETURN
    DIVIDE (
        SUMX (
            FILTER (
                filtered,
                COUNTROWS (
                    INTERSECT ( ROW ( "Row", [RowField], "Column", [ColumnField] ), highlighted)
                ) > 0
            ),
            [ValueField]
        ),
        CALCULATE ( SUM ( Table[ValueField] ), ALLSELECTED ( Table ) ),
        -1
    )

Regards,

Xiaoxin Sheng

Community Support Team _ Xiaoxin
If this post helps, please consider accept as solution to help other members find it more quickly.
amitchandak
Super User
Super User

@Anonymous 

Create a new matrix to return the sum/count of the value whenever the color light green color supposes to return. Almost same measure return sum/count of measure for light green and blank() for others

Anonymous
Not applicable

@amitchandak how do i go about doing that? Whenever I try to use sum(count([Movement Color])), PowerBI errors out because the movement color function only returns string values of "lightgreen" or "". 

I am not asking to the sum of count that. In all you ifs return a sum/count of measure instead of green. In place of other return blank()

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.