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

Grow your Fabric skills and prepare for the DP-600 certification exam by completing the latest Microsoft Fabric challenge.

Reply
o59393
Post Prodigy
Post Prodigy

Count if with a measure

Hi

 

Is it possible to create a count if with a measure?

 

In the image below I have a capacity planning process with different activities (drilled down).

 

o59393_0-1714307047947.png

 

 

 

The rule is simple, if the % on each of the rows is above or equal to 0.8% then 1, else 0.

 

Also it should make the sum of the 1's for the process.  Hence the activities: capacity assessment, demand alignment and standard routines are the only ones who meet the criteria and should have a 1 next to each row, and the capacity assessment process should have a 3 (the sum of the 3 activities with a 1)

 

How can this be done in a dax?

 

The % column of the image has the following dax:

 

 

Non Duplicate Hours Process/Activity 3 = 

DIVIDE(
[Non Duplicate Hours Process/Activity Numerator],
[Non Duplicate Hours Process/Activity Denominator 3])

 

 

Thanks. 

 

 

 

 

 

13 REPLIES 13
lbendlin
Super User
Super User

You cannot measure a measure directly. Either materialize it first, or create a separate measure that implements the entire business logic.

 

@lbendlin 

 

Think I am getting closer:

o59393_0-1714309541607.png

 

 

Any idea here why the red shows up ?

I'd go with @ITManuel 's approach.  Is that not sufficient?

Hi @lbendlin 

 

Any idea here how to fix?

 

o59393_2-1714311686574.png

 

 

thanks.

Hi @lbendlin  @ITManuel 

 

It shows empty:

 

o59393_0-1714311563899.png

 

 

Where:

 

Count IF 2 = 
VAR _T1 = 
FILTER (
    ADDCOLUMNS (
        VALUES ( Template[Facet] ),
        "@%", [Non Duplicate Hours Process/Activity 3]
    ),
    [@%] >= 0.8
)
VAR _Result = COUNTROWS ( _T1 )
RETURN
_Result

 

The table I am using has the following fields:

 

o59393_1-1714311618974.png

 

 

Any idea what could be wrong?

 

thanks.

 

Hi @lbendlin 

 

With the second option you mention.

 

The dax I am trying to reference has these 2 pieces:

 

Non Duplicate Hours Process/Activity Numerator = 

SUMX(
    SUMMARIZE(
        Template,
        Template[Merged],
        Template[Hours by Year]
        ),       
        Template[Hours by Year]
)

 

Could I have the if statetement incorporating these 2 measures within the dax?

 

thanks.

ITManuel
Responsive Resident
Responsive Resident

Hi @o59393 ,

 

not sure if I understood correctly, but if you want to count the facets which have & equal or greater to 0,8% you can try the following:

 

Count IF =
VAR _T1 = 
FILTER (
    ADDCOLUMNS (
        VALUES ( Table[Facet] ),
        "@%", [Non Duplicate Hours Process/Activity 3]
    ),
    [@%] >= 0.8
)
VAR _Result = COUNTROWS ( _T1 )
RETURN
_T1

Hi @ITManuel 

 

I got this message:

o59393_0-1714309091538.png

 

Thanks.

 

ITManuel
Responsive Resident
Responsive Resident

Sorry there is a mistake from my side. 

Use _Result after RETURN instead of _T1

Hi @lbendlin  @ITManuel 

 

I am getting closer to the solution.

 

I used:

Count IF = 

var _x = 
SUMX(
    SUMMARIZE(
        Template,
        Template[Merged],
        Template[Hours by Year]
        ),       
        Template[Hours by Year])

var _y = 
        CALCULATE(
    [Non Duplicate Hours Process/Activity Numerator],
        ALLEXCEPT(
            Template,
            Template[Function],
            Template[Area],
            Template[Name]))
var _z = 

DIVIDE(_x,_y)

RETURN

IF(_z>=0.01,1,0)

 

It works well, the only thing still not doing is the sum of those who are above 1.

 

In the image below:

 

o59393_3-1714312869880.png

 

 

Next to capacity planning there should be a 5 which is the sum of the activities.

 

Any idea?

 

Thanks.

ITManuel
Responsive Resident
Responsive Resident

What you are doing is not counting anything, but calculating your [ Count IF] measure for each line and its specific filter context in the visual. 

Try this:

 

 

COUNT IF =
VAR _T1 =
    FILTER (
        ADDCOLUMNS (
            VALUES ( Template[Facet] ),
            "@%",
                VAR _X =
                    SUMX (
                        SUMMARIZE ( Template, Template[Merged], Template[Hours by Year] ),
                        Template[Hours by Year]
                    )
                VAR _Y =
                    CALCULATE (
                        [Non Duplicate Hours Process/Activity Numerator],
                        ALLEXCEPT ( Template, Template[Function], Template[Area], Template[Name] )
                    )
                VAR _Z =
                    DIVIDE ( _X, _Y )
                RETURN
                    _Z
        ),
        [@%] >= 0.01
    )
VAR _Result =
    COUNTROWS ( _T1 )
RETURN
    _Result

 

 

Hi @ITManuel 

 

Tried the measure but still not getting the sum. For example here should be 13 and I am getting 1:

 

o59393_0-1714346625019.png

 

Could it be missing sumx?

 

THanks.

Hi @ITManuel 

 

Thanks, closer. But the total for Tier 1: Process is showing one as seen below:

o59393_0-1714327085159.png

 

 

Capacity planning from Tier 1: Process should have a result of 5 because 5 activities (Tier 2) contain a 1.

 

How can it make the sum of the 1s?

 

Thanks!

Helpful resources

Announcements
RTI Forums Carousel3

New forum boards available in Real-Time Intelligence.

Ask questions in Eventhouse and KQL, Eventstream, and Reflex.

MayPowerBICarousel1

Power BI Monthly Update - May 2024

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

Europe Fabric Conference

Europe’s largest Microsoft Fabric Community Conference

Join the community in Stockholm for expert Microsoft Fabric learning including a very exciting keynote from Arun Ulag, Corporate Vice President, Azure Data.