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

Did you hear? There's a new SQL AI Developer certification (DP-800). Start preparing now and be one of the first to get certified. Register now

Reply
Anonymous
Not applicable

Count over Measure with Conditions

Hi guys.

 

I am trying to get a Count over a measure with specific conditions, like value between 20 and 25% and value over 25%.

 

I honestly have no clue on how to do it. I built this table to picture what I am looking for, I think it's clearer this way:

 

Untitled.png

 

 

 

 

 

 

 

 

 

 

 

 

Any ideas?

 

I don't need all the code, maybe with a few hints I can do it.

 

Thanks in advance! Smiley Happy

1 ACCEPTED SOLUTION

Hi @Anonymous,

 

Based on the PBIX file you shared I believe that the  issue is based on context because in the measure you created you are making based on Name and Date but on the count of the percentages you are not giving that same context so the result is not correct.

 

Create a column based on the date from your table:

 

MONTH = FORMAT(TABLE[DATE];"mm-yyyy")

Then create the following measure:

 

COUNT % 20 - 25 =
COUNTROWS (
    FILTER (
        SUMMARIZE (
            ALL ( TABLE[NAME]; TABLE[MONTH] );
            TABLE[NAME];
            TABLE[MONTH];
            "% Count"; [MEASURE TO BE COUNTED]
        );
        [MEASURE TO BE COUNTED] >= 0,2
            && [MEASURE TO BE COUNTED] <= 0,25
    )
)

 

 

Believe this should work, but check the PBIX file I have return to you trough private message.

 

 

Regards,

MFelix


Regards

Miguel Félix


Did I answer your question? Mark my post as a solution!

Proud to be a Super User!

Check out my blog: Power BI em Português





View solution in original post

12 REPLIES 12
ramzan11b
Regular Visitor

Awsome and Fantastic.
Thanks very much. I was facing a problem in such a measure. This Post solved my probem.🙂
👍👍

v-yuta-msft
Community Support
Community Support

Hi svalen ,

 

"I am trying to get a Count over a measure with specific conditions, like value between 20 and 25% and value over 25%."

<--- What's your expected result? Could you give some example? In addtion, Could you share a mockup with some dummy data for further analysis?

 

 

Regards,

Jimmy Tao

 

MFelix
Super User
Super User

Hi @Anonymous,

 

You need to make a aggregate you measure within a summarize table.

 

Try something like this:

 

COUNT MEASURE =
CALCULATE (
    COUNTROWS (
        FILTER (
            SUMMARIZE ( ALL ( Table1[Type]; Table1[Type] ); Table1[Type]; "MEASURE TO COUNT"; [MEASURE] );
            [MEASURE TO COUNT] < 0,25
                && [MEASURE TO COUNT] > 0,2
        )
    )
)

Adjust the coding to what you need.

 

Regards,

MFelix


Regards

Miguel Félix


Did I answer your question? Mark my post as a solution!

Proud to be a Super User!

Check out my blog: Power BI em Português





Anonymous
Not applicable

@MFelix, the Great:

 

I tried your code and it didn't work, it returns the same value for all the Types. I also tried the alternative on comment below.

 

XXX = 
CALCULATE (
    COUNTROWS (
        FILTER (
            SUMMARIZE ( ALL ( ''Table1'[Type]; ''Table1'[Type] ); ''Table1'[Type]; "MEASURE TO COUNT"; [MEASURE] );
            [MEASURE TO COUNT] <= 0,25
                && [MEASURE TO COUNT] >= 0,2
        )
    )
)

/*
XXX = 
CALCULATE (
    COUNTROWS (
        FILTER (
            ADDCOLUMNS (
                SUMMARIZE (
                    ALL ( ''Table1'[Type] );
                    ''Table1'[Type]
                );
                "MEASURE TO COUNT"; [MEASURE]
            );
            [MEASURE TO COUNT] >= 0,2
                && [MEASURE TO COUNT] <= 0,25
        )
    )
)
*/

Any thoughts?

@Anonymous

 

Try this one

 

Measure =
COUNTROWS (
    FILTER (
        VALUES ( Table1[Name] ),
        [MEASURE TO COUNT] < 0.25
            && [MEASURE TO COUNT] > 0.2
    )
)
Anonymous
Not applicable

@Zubair_Muhammad

 

Thanks for the suggestion, but no luck still, it returns 1 for every Type.

 

I also tried like:

 

XXX =
COUNTROWS (
    FILTER (
        ADDCOLUMNS (
            VALUES ( 'Table1'[Type] );
            "MEASURE TO COUNT"; [MEASURE]
        );
        [MEASURE TO COUNT] <= 0,25
            && [MEASURE TO COUNT] >= 0,2
    )
)

We are missing something here...

Hi @Anonymous,

 

Based on the PBIX file you shared I believe that the  issue is based on context because in the measure you created you are making based on Name and Date but on the count of the percentages you are not giving that same context so the result is not correct.

 

Create a column based on the date from your table:

 

MONTH = FORMAT(TABLE[DATE];"mm-yyyy")

Then create the following measure:

 

COUNT % 20 - 25 =
COUNTROWS (
    FILTER (
        SUMMARIZE (
            ALL ( TABLE[NAME]; TABLE[MONTH] );
            TABLE[NAME];
            TABLE[MONTH];
            "% Count"; [MEASURE TO BE COUNTED]
        );
        [MEASURE TO BE COUNTED] >= 0,2
            && [MEASURE TO BE COUNTED] <= 0,25
    )
)

 

 

Believe this should work, but check the PBIX file I have return to you trough private message.

 

 

Regards,

MFelix


Regards

Miguel Félix


Did I answer your question? Mark my post as a solution!

Proud to be a Super User!

Check out my blog: Power BI em Português





Anonymous
Not applicable

@MFelix@v-yuta-msft@Zubair_Muhammad

 

Thanks everyone for the contribution, the issue is now solved, @MFelix solved it perfectly!

 

Cheers!

Anonymous
Not applicable

@MFelixand @Zubair_Muhammad

 

BTW, the existing measure is something like this:

 

MEASURE =
VAR X1 =
    CALCULATE ( [SO UNITS]; 'DimP'[COD] = 111 )
        + CALCULATE ( [SO UNITS]; 'DimP'[COD] = 222 )
VAR X2 =
    CALCULATE ( [SO UNITS]; 'DimP'[COD2] = 333 )
        + CALCULATE ( [SO UNITS]; 'DimP'[COD2] = 444 )
RETURN
    DIVIDE ( X1; X2 )

Can you share you PBIX with me?


Regards

Miguel Félix


Did I answer your question? Mark my post as a solution!

Proud to be a Super User!

Check out my blog: Power BI em Português





Anonymous
Not applicable

Claro!

send it trough private message 😄


Regards

Miguel Félix


Did I answer your question? Mark my post as a solution!

Proud to be a Super User!

Check out my blog: Power BI em Português





Helpful resources

Announcements
April Power BI Update Carousel

Power BI Monthly Update - April 2026

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

Fabric SQL PBI Data Days

Data Days 2026 coming soon!

Sign up to receive a private message when registration opens and key events begin.

New to Fabric survey Carousel

New to Fabric Survey

If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.