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
Jwit
Frequent Visitor

Selecting a group by one value and creating an average

I'm fairly new to Power BI and writing dax, but reading answers in this forum has helped me a lot.  So, faced with a new problem I can't work out I thought I'd ask for some help.

I have a spreadsheet of data that records answers (yes/no) regarding shortages in many facilities.  Each facility is asked about 8 types of shortages.  I am trying to calculate out what the percentage of facilities that have shortages is.  I wrote a simple measure that does this:

% YES today =

DIVIDE (

 CALCULATE ( COUNT ( Table1[shortage]), 'Table1'[shortage] = "YES" ),

 CALCULATE ( COUNT ( Table1 [shortage] ), ALLSELECTED ( Table1[shortage] ) )

)
However, I then realized that one of the things I want to know is the percentage of facilities that have any type of shortage. So if my
data looked like:

Facility NametypeShortage
Facility 1Ano
Facility 1Bno
Facility 1Cyes
Facility 2Ano
Facility 2Bno
Facility 2Cno
Facility 3Ano
Facility 3Bno
Facility 3Cno

My measure returns an average of 11%, but I need it to be 33% as one of the three facilities has a shortage of type C.
I am just not sure how to group the facilites by name and then have any yes designate that facility as yes overall.

Any help is appreciated, thanks in advance.

1 ACCEPTED SOLUTION

Hi,

You may download my PBI file from here.

Hope this helps.

Untitled.png


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/

View solution in original post

7 REPLIES 7
mahoneypat
Employee
Employee

The measure below should return a result of 33%

 

% Facilities with Shortage =
VAR shortagefacilities =
    COUNTROWS (
        FILTER (
            ALLSELECTED ( Table1[Facility] ),
            NOT (
                ISBLANK (
                    CALCULATE (
                        COUNT ( Table1[shortage] ),
                        'Table1'[shortage] = "YES"
                    )
                )
            )
        )
    )
VAR facilities =
    COUNTROWS (
        ALLSELECTED ( Table1[Facility] )
    )
RETURN
    DIVIDE (
        shortagefacilities,
        facilities
    )

 

Regards,

Pat

 

 

 





Did I answer your question? Mark my post as a solution! Kudos are also appreciated!

To learn more about Power BI, follow me on Twitter or subscribe on YouTube.


@mahoneypa HoosierBI on YouTube


@mahoneypat 

For some reason this measure seems to give me the exact same percentage for every facility in my data.  I'll have to dig in to the data and see why that might be happening.

Ashish_Mathur
Super User
Super User

Hi,

What result would you expect (share the numerator and denominator speprately), if your data was like this (my edited cells are highlighted in yellow)

Untitled.png

 


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/

@Ashish_Mathur 

I would expect this result to have a numerator of 2 and a denominator of 3 so 2 of 3 facilities would now have shortages.

Hi,

You may download my PBI file from here.

Hope this helps.

Untitled.png


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/

@Ashish_MathurThis is exactly what I was looking for, thank you very much!

In case anyone else is wondering it was a three measure combination of:

Count of facilities = DISTINCTCOUNT(Data[Facility Name])

Facilities with shortages = CALCULATE(COUNTROWS(Data),Data[Shortage]="Yes")

Measure = COUNTROWS(FILTER(VALUES(Data[Facility Name]),[Facilites with shortages]>0))/[Count of facilities]

 

You are welcome.


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/

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.