Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Calculate % based on a combination of count and stored values - Power BI

I have a basic table that looks like this:

 DayNo. Customer    AgentsInvolved  CallID
   0      AAA              1        1858
   0      AAA              3        1859
   2      AAA              1        1860
   0      BBB              2        1862
   0      CCC              1        1863
   0      DDD              3        1864
   9      DDD              1        1865
   9      DDD              4        1866

I need to be able to find the % of customers who only contacted only once, and spoke to 1 agent only. So from the above example, out of 4 distinct customers only customer CCC falls into this category (1 call, 1 AgentInvolved)

So the Desired result would be: 1/4 or 25%

How can I create a Power BI measure to do this calc?

like image 244
dragonfury2 Avatar asked Dec 06 '25 22:12

dragonfury2


2 Answers

Try this measure:

Desired Result =
VAR summarizetable =
    SUMMARIZECOLUMNS (
        'table'[Customer],
        "Calls", COUNT ( 'table'[CallID] ),
        "Agents", SUM ( 'table'[AgentsInvolved] ),
        "Day", SUM ( 'table'[DayNo.] )
    )
RETURN
    COUNTROWS (
        FILTER ( summarizetable, [Calls] = 1 && [Agents] = 1 && [Day] = 0 )
    )
        / COUNTROWS ( summarizetable )

The summarized table created on the fly in VAR summarizetable looks like this:

enter image description here

like image 56
Marco Vos Avatar answered Dec 09 '25 01:12

Marco Vos


Here's another approach:

Measure = 
SUMX(
    VALUES(Table2[Customer]),
    CALCULATE(
        IF(
            DISTINCTCOUNT(Table2[CallID]) = 1 &&
              SUM(Table2[AgentsInvolved]) = 1,
            1,
            0
        ),
    Table2[DayNo.] = 0
    )
) /
DISTINCTCOUNT(Table2[Customer])

If you want to exclude the 0 day rows in the denominator as well, replace the last line with

CALCULATE(DISTINCTCOUNT(Table2[Customer]), Table2[DayNo.] = 0)
like image 22
Alexis Olson Avatar answered Dec 09 '25 03:12

Alexis Olson