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
mfriedrich228
Regular Visitor

Measure that calculates the % of answers per year while respecting site and global filter

Hi everyone, 

I have a table with the following structure:

QuestionAnswerYearTeamCountSortingID
Are you happy with your job?   Yes2021   Team Development11
Are you happy with your job?No2020Team HR13
Are you happy with your job?Not sure2019Team Marketing12
Do you like your boss?Yes2021Team PR11
Do you like your boss?Not sure2020Team HR12
Do you like your boss?No2019Team Development13


Now I would like to create a Measure that calculates % for every answer per year while respecting that there is sitewide filter for the team and page filter for the question. At the end I want to display those results in a bar chart where the calculated value is the value, the legend is the year and the axis are the answers. So if a value exists I want to display bars per answer, one for every year. I tried to play around with measures a bit and also tried to modify one I got here as a helping answer but I couldn't get it properly to work. That's what I have right now:

 

Question % = Divide(
count( 'Top 10 Questions for all Teams'[Answer] ),
Calculate(
count( 'Top 10 Questions for all Teams'[Answer] ),
ALLEXCEPT('Top 10 Questions for all Teams','Top 10 Questions for all Teams'[Year])
)
)

 

I would be thankful for any help or hints what I might do wrong here or what I need to change in order to make it work properly.

KInd regards

Maximilian

3 REPLIES 3
AlexisOlson
Super User
Super User

Try adding ALLSELECTED to preserve the filter context from the report and page filters.

Question % =
DIVIDE (
    COUNT ( 'Top 10 Questions for all Teams'[Answer] ),
    CALCULATE (
        COUNT ( 'Top 10 Questions for all Teams'[Answer] ),
        ALLSELECTED (),
        ALLEXCEPT (
            'Top 10 Questions for all Teams',
            'Top 10 Questions for all Teams'[Year]
        )
    )
)

That calculates wrong results, maybe to make it easier for you to understand what I would like to get, I have a small calculation example:

Team HR:
2021: 10 Votes, 5 Yes, 2 Not sure, 3 No -> 50% Yes, 20% Not sure, 30% No
2020: 10 Votes, 3 Yes, 2 Not sure, 5 No -> 30% Yes, 20% Not sure, 50% No
2019: 10 Votes, 6 Yes, 4, Not sure -> 60% Yes, 40% Not sure, 0% No

I hope this illustrates my goal better than my original post, because I think the blaming is on my requirements and certainly not your DAX skills 🙂

Kind regards

Maximilian

With the data in your post, you could put Year on rows and Answer on columns to get this

AlexisOlson_0-1643665382184.png

Using this measure:

Question % = 
DIVIDE (
    COUNT ( 'Top 10 Questions for all Teams'[Answer] ),
    CALCULATE (
        COUNT ( 'Top 10 Questions for all Teams'[Answer] ),
        ALL ( 'Top 10 Questions for all Teams'[Answer] )
    )
)

 

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.

Top Solution Authors