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
chrisgehm
Helper III
Helper III

Accumulated count if

Hi everyone!

 

I'm having some troubles while calculating some values.

I was doing it in excel with dynamic tables, but now I want to make a step forward and start using Power BI 🙂

 

I have this table

 

MonthYearCond1Cond2Cond3
120170OpenA
120170OpenA
220170CloseA
220171OpenA
320171CloseB
320170OpenB

 

What I need is the following:

 

I need show per Month & Year this division:

 

Count(Cond1 = 0 && Cond2 = Open && Cond3 = A) / Count (Cond1  = 0 && Cond2 = Open)

 

Is it possible?


Kind regards!

1 ACCEPTED SOLUTION
Vvelarde
Community Champion
Community Champion

@chrisgehm

 

Hi, you can try to obtain your result with this:

 

 

Count to Cond1 is 0 and Cond2 Open and Cond3 is A =
COUNTROWS (
    FILTER (
        Table1,
        Table1[Cond1] = 0
            && Table1[Cond2] = "Open"
            && Table1[Cond3] = "A"
    )
)
Count to Cond1 is 0 and Cond2 Open =
COUNTROWS ( FILTER ( Table1, Table1[Cond1] = 0 && Table1[Cond2] = "Open" ) )
Result =
DIVIDE (
    [Count to Cond1 is 0 and Cond2 Open and Cond3 is A],
    [Count to Cond1 is 0 and Cond2 Open],
    BLANK ()
)

With 3 measure or All together in a single Measure

 

Measure =
VAR Count_to_Cond1_is_0_and_Cond2_Open_and_Cond3_is_A =
    COUNTROWS (
        FILTER (
            Table1,
            Table1[Cond1] = 0
                && Table1[Cond2] = "Open"
                && Table1[Cond3] = "A"
        )
    )
VAR Count_to_Cond1_is_0_and_Cond2_Open =
    COUNTROWS ( FILTER ( Table1, Table1[Cond1] = 0 && Table1[Cond2] = "Open" ) )
RETURN
    DIVIDE (
        Count_to_Cond1_is_0_and_Cond2_Open_and_Cond3_is_A,
        Count_to_Cond1_is_0_and_Cond2_Open,
        BLANK ()
    )

Count-If.png

 

Regards

 

Victor

Lima - Peru

 

 




Lima - Peru

View solution in original post

4 REPLIES 4
Vvelarde
Community Champion
Community Champion

@chrisgehm

 

Hi, you can try to obtain your result with this:

 

 

Count to Cond1 is 0 and Cond2 Open and Cond3 is A =
COUNTROWS (
    FILTER (
        Table1,
        Table1[Cond1] = 0
            && Table1[Cond2] = "Open"
            && Table1[Cond3] = "A"
    )
)
Count to Cond1 is 0 and Cond2 Open =
COUNTROWS ( FILTER ( Table1, Table1[Cond1] = 0 && Table1[Cond2] = "Open" ) )
Result =
DIVIDE (
    [Count to Cond1 is 0 and Cond2 Open and Cond3 is A],
    [Count to Cond1 is 0 and Cond2 Open],
    BLANK ()
)

With 3 measure or All together in a single Measure

 

Measure =
VAR Count_to_Cond1_is_0_and_Cond2_Open_and_Cond3_is_A =
    COUNTROWS (
        FILTER (
            Table1,
            Table1[Cond1] = 0
                && Table1[Cond2] = "Open"
                && Table1[Cond3] = "A"
        )
    )
VAR Count_to_Cond1_is_0_and_Cond2_Open =
    COUNTROWS ( FILTER ( Table1, Table1[Cond1] = 0 && Table1[Cond2] = "Open" ) )
RETURN
    DIVIDE (
        Count_to_Cond1_is_0_and_Cond2_Open_and_Cond3_is_A,
        Count_to_Cond1_is_0_and_Cond2_Open,
        BLANK ()
    )

Count-If.png

 

Regards

 

Victor

Lima - Peru

 

 




Lima - Peru

Hi @Vvelarde It worked with the 3 mesasures separated. With the other the result it made no sense.


Thanks!!!


Kind regards

BILASolution
Solution Specialist
Solution Specialist

Hi @chrisgehm

 

Try this...

 

Open.png

 

 

 

Meaures:

 

0, Open and A = IF(ISBLANK(CALCULATE(COUNTROWS(Table1);Table1[Cond1] = 0;Table1[Cond2] = "Open";Table1[Cond3] = "A"));0;CALCULATE(COUNTROWS(Table1);Table1[Cond1] = 0;Table1[Cond2] = "Open";Table1[Cond3] = "A"))

 

0 and Open = IF(ISBLANK(CALCULATE(COUNTROWS(Table1);Table1[Cond1] = 0;Table1[Cond2] = "Open"));0;CALCULATE(COUNTROWS(Table1);Table1[Cond1] = 0;Table1[Cond2] = "Open"))

 

Division = IF(ISBLANK(DIVIDE([0, Open and A];[0 and Open]));0;DIVIDE([0, Open and A];[0 and Open]))

 

Regards

BILASolution

Hi @BILASolution!

Thanks for the answer.

It seems to be working, but at some piont I can notice an error:

 

This is my data set

 

Captura.PNG

 

So, with the first 2 measures, I've got 67 and 34

But when I make the division, it makes no sense, since the result is 79.83. It should be 0.50

 

Is there any mistake I'm making?

 

Kind regards

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.