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
nicolasvargas
Helper I
Helper I

How to calculate a percentage count of an average

Hello, 

 

I have a metric that calculates the average perf for each month:

 

AvgM = AVERAGEX(KEEPFILTERS(VALUES('db'[Date])),[Perf])
 
I would like to count the proportion of months in which AvgM is > 0, but I can't manage to find the correct way to formulate the DAX.
 
Thx
1 ACCEPTED SOLUTION

Hi, @nicolasvargas 

Add a new measure as below:

Percentage =
VAR tab =
    SUMMARIZE ( 'Table', 'Table'[Date], "AvgM", 'Table'[AvgM] )
VAR a =
    COUNTROWS ( tab )
VAR b =
    COUNTROWS ( FILTER ( tab, [AvgM] > 0 ) )
RETURN
    b / a

140.png

 

Best Regards,
Community Support Team _ Eason

View solution in original post

3 REPLIES 3
lbendlin
Super User
Super User

Please provide sanitized sample data that fully covers your issue. Paste the data into a table in your post or use one of the file services. Please show the expected outcome.

With a sample data like this;

 

DateValue
01/01/2001     -1
01/01/2001     2
01/01/2001     3
02/01/2001     -1
02/01/2001     -2
02/01/2001     2

 

The first metric would help me outputing this as a result:

DateAvg Value
01/01/2001     1.33
02/01/2001     -0.33

 

Now, what I would like to do is to count the number of months in which this value is over 0. In this case it should output 50%

Hi, @nicolasvargas 

Add a new measure as below:

Percentage =
VAR tab =
    SUMMARIZE ( 'Table', 'Table'[Date], "AvgM", 'Table'[AvgM] )
VAR a =
    COUNTROWS ( tab )
VAR b =
    COUNTROWS ( FILTER ( tab, [AvgM] > 0 ) )
RETURN
    b / a

140.png

 

Best Regards,
Community Support Team _ Eason

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.