budding pro
budding pro

Reputation: 195

find percentage per unique fields value in a long-format table in powerbi dax

I have the following snip of a table in power bi:

columns: ['id','fields','io','status','value']

pbi_table

I would like to calculate for each unique value of the column field per id with a condition that the status value is complete.

+----+---------+---------+-----+
| id | field   | status  |  %  |
--------------------------------
| 112|    zip  | complete| 60  |
| 112| gender  | complete| 54  |
...
| 245|   zip   | complete| 85  |
+----+=--------+---------+-----+

the idea is (sum of complete) / (sum of complete+missing+error) per id.

I am not sure how to approach this with a long format table.

Upvotes: 0

Views: 469

Answers (2)

Ozan Sen
Ozan Sen

Reputation: 2615

You can use this code as a measure:

Completed_Percent =
VAR SummaryTable =
    ADDCOLUMNS (
        FILTER (
            SUMMARIZE ( Table1, Table1[id], Table1[fields], Table1[status] ),
            Table1[status] = "complete"
        ),
        "%",
            DIVIDE (
                100 * CALCULATE ( SUM ( Table1[value] ) ),
                CALCULATE ( SUM ( Table1[value] ), ALL ( Table1 ) )
            )
    )
VAR Result =
    SUMX ( SummaryTable, [%] )
RETURN
    Result

Then Create a table or Matrix, Put [id], [field],[status] into row area, and put "Completed_Percent" measure in the value area. Done!

If we test it:

FDFG

Upvotes: 1

Umut K
Umut K

Reputation: 1388

try this :

   Completed % =
CALCULATE (
    SUM ( 'Table (2)'[value] ),
    ALLEXCEPT ( 'Table (2)', 'Table (2)'[id], 'Table (2)'[fields] ),
    'Table (2)'[status] = "Complete"
)
    / CALCULATE (
        SUM ( 'Table (2)'[value] ),
        ALLEXCEPT ( 'Table (2)', 'Table (2)'[id] )
    )

complete %

Upvotes: 2

Related Questions