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

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends September 15. Request your voucher.

Reply
AxlCox
Helper I
Helper I

Is it possible to calculate a percentage based on displayed values?

Simply put, my data set had years worth of data in rows. On my visuals, I've created simple cards to display count totals and filtering to only show rows created this year. Each of these tasks (the rows) have an SLA, which I display using another card, filtered by both created this year AND SLA Breached is TRUE. So it basically looks like this:

 

Total YTD

823
YTD SLA Breached
388

 

Rather than showing the breached as a total, I need it to show as a percentage of that 823 total. So it should really look like

 

Total YTD

823
YTD SLA Breached
47%

 

From my research, it seems like this all has to be calculated as a measure but I'm pretty green with DAX. If I could do a simple calculation using the actual pre-filtered visuals, that would rock, but as far as I can tell, that's not an option. Any insight would be appreciated! 

1 ACCEPTED SOLUTION

@AxlCox  try this

M3 =
VAR _0 =
    ADDCOLUMNS ( t2, "@year", YEAR ( [Created Date] ) )
VAR _1 =
    FILTER ( _0, [@year] = MAXX ( _0, [@year] ) )
VAR _2 =
    ADDCOLUMNS (
        _1,
        "@ratio",
            DIVIDE (
                COUNTX ( FILTER ( _1, [Duration] > 30 ), [Duration] ),
                COUNTX ( _1, [Duration] )
            )
    )
RETURN
    MAXX ( _2, [@ratio] )
Did I answer your question? Mark my post as a solution!
Proud to be a Super User!
My custom visualization projects
Plotting Live Sound: Viz1
Beautiful News:Viz1, Viz2, Viz3
Visual Capitalist: Working Hrs

View solution in original post

13 REPLIES 13
AxlCox
Helper I
Helper I

The actual data is highly confidential, but here's some dummy data that should be relevant to what I'm looking for.

 

Task NoCreated DateSLA Breached?
11/3/2019No
22/4/2020Yes
32/23/2021Yes
45/4/2018No
57/4/2018No
612/22/2020No
77/6/2021No
811/22/2020Yes
99/9/2020Yes
1010/11/2021Yes

 

Using this data, I'd like to have two cards displayed like this (based on this data):

 

# Year To Date

3

 

% Year To Date Breached

67%

 

Right now, I'm using a filter on the data to show the # year to date. On the second card, I'm currently using a filter to only show those from this year AND SLA Breached = true.

 

To get the percentage of % Year To Date Breached, it's obviously simple division, but I am ignorant on how to show a calculation based on filtered data.

@AxlCox  why 

# Year To Date = 3

There are 4 years in the data {2018,2018,2020,2021}. By # Year To Date  do you intend to show the total count of all distinct years?

 

Also, why 

% Year To Date Breached = 67%

what is the numerator and denominator and how are they calculated?

If the above is true it should be 50% = {2020="Yes" and 2021="Yes" out of 2018,2018,2020,2021}

 

Did I answer your question? Mark my post as a solution!
Proud to be a Super User!
My custom visualization projects
Plotting Live Sound: Viz1
Beautiful News:Viz1, Viz2, Viz3
Visual Capitalist: Working Hrs

Sorry - I didn't clarify. I am only targeting tasks created THIS year, so that's where the 3 comes from.

 

67% is coming from 2/3. (2 tasks SLA BREACHED is TRUE [Among tasks in 2021] / 3 tasks in 2021)

 

@AxlCox  and what About  # Year To Date = 3

 

How are you getting that?

Did I answer your question? Mark my post as a solution!
Proud to be a Super User!
My custom visualization projects
Plotting Live Sound: Viz1
Beautiful News:Viz1, Viz2, Viz3
Visual Capitalist: Working Hrs

Year To Date may be the wrong identification stated. I'm just looking for thos created in 2021 (1/1/21 - today), not 11/3/20 - 11/3/21.

 

So just these:

 

Task NoCreated DateSLA Breached?
11/3/2019No
22/4/2020Yes
32/23/2021Yes
45/4/2018No
57/4/2018No
612/22/2020No
77/6/2021No
811/22/2020Yes
99/9/2020Yes
1010/11/2021Yes

 

@AxlCox  

 

M1 =
VAR _0 =
    ADDCOLUMNS ( 'Table', "@year", YEAR ( [Created Date] ) )
VAR _1 =
    FILTER ( _0, [@year] = MAXX ( _0, [@year] ) )
RETURN
    COUNTROWS ( _1 )


M2 =
VAR _0 =
    ADDCOLUMNS ( 'Table', "@year", YEAR ( [Created Date] ) )
VAR _1 =
    FILTER ( _0, [@year] = MAXX ( _0, [@year] ) )
VAR _2 =
    ADDCOLUMNS (
        _1,
        "@ratio",
            DIVIDE (
                COUNTX ( FILTER ( _1, [SLA Breached?] = "Yes" ), [SLA Breached?] ),
                COUNTX ( _1, [SLA Breached?] )
            )
    )
RETURN
    MAXX ( _2, [@ratio] )

 

smpa01_0-1635958256783.png

 Pbix is attached

Did I answer your question? Mark my post as a solution!
Proud to be a Super User!
My custom visualization projects
Plotting Live Sound: Viz1
Beautiful News:Viz1, Viz2, Viz3
Visual Capitalist: Working Hrs

Making some progress here....

 

M1 is working (the column names in the actual data differ, but I got it figured out). 

 

However M2, isn't working but I take full fault as I provided the wrong criteria. Using the same data structure as an example, but modified...:

 

Task NoCreated DateDuration (days)
11/3/20195
22/4/202011
32/23/202145
45/4/201817
57/4/201819
612/22/202025
77/6/20218
811/22/202028
99/9/202025
1010/11/202156

 

The percentage I need to show is the Percent of these rows that are 1) Created in 2021 and 2) Have duration > 30. 

 

In this example, it would still be 67%.

 

2 <- 2 rows created in 2021 AND >30 days duration

/

3 <- 3 rows created in 2021

 

I tried taking a crack at modifying the DAX as I thought it would be, but no dice.

@AxlCox  try this

M3 =
VAR _0 =
    ADDCOLUMNS ( t2, "@year", YEAR ( [Created Date] ) )
VAR _1 =
    FILTER ( _0, [@year] = MAXX ( _0, [@year] ) )
VAR _2 =
    ADDCOLUMNS (
        _1,
        "@ratio",
            DIVIDE (
                COUNTX ( FILTER ( _1, [Duration] > 30 ), [Duration] ),
                COUNTX ( _1, [Duration] )
            )
    )
RETURN
    MAXX ( _2, [@ratio] )
Did I answer your question? Mark my post as a solution!
Proud to be a Super User!
My custom visualization projects
Plotting Live Sound: Viz1
Beautiful News:Viz1, Viz2, Viz3
Visual Capitalist: Working Hrs

Hrm, yeah that's actually what I entered. I'm getting a value, but it's coming back at 1%.  It should be 52.6%.

 

Here's my actual code, with the true column names that I subbed in:

 

 

% >30 Days = 
VAR _0 =
    ADDCOLUMNS ( 'RFPs', "Calc Year", YEAR ( [Created] ) )
VAR _1 =
    FILTER ( _0, [Calc Year] = MAXX ( _0, [Calc Year] ) )
VAR _2 =
    ADDCOLUMNS (
        _1,
        "@ratio",
            DIVIDE (
                COUNTX ( FILTER ( _1, [Duration of RFP] > 30 ), [Duration of RFP] ),
                COUNTX ( _1, [Duration of RFP] )
            )
    )
RETURN
    MAXX ( _2, [@ratio] )

 

 

The M1 formula returned 823, which is the correct count for 2021 entries, matching my original filtered value.

M2 should be coming back at 52.6%, based off of 433 rows having both 1) Been created in 2021 and 2) Having a duration >30. 

 

Here are the visual filters producing that 433 number:

 

2021-11-03_14h44_02.png

@AxlCox  I am acting on the sample data and the measure is absolutely working..see attached

Did I answer your question? Mark my post as a solution!
Proud to be a Super User!
My custom visualization projects
Plotting Live Sound: Viz1
Beautiful News:Viz1, Viz2, Viz3
Visual Capitalist: Working Hrs

Follow up question to this query:

% >30 Days = 
VAR _0 =
    ADDCOLUMNS ( 'RFPs', "Calc Year", YEAR ( [Created] ) )
VAR _1 =
    FILTER ( _0, [Calc Year] = MAXX ( _0, [Calc Year] ) )
VAR _2 =
    ADDCOLUMNS (
        _1,
        "@ratio",
            DIVIDE (
                COUNTX ( FILTER ( _1, [Duration of RFP] > 30 ), [Duration of RFP] ),
                COUNTX ( _1, [Duration of RFP] )
            )
    )
RETURN
    MAXX ( _2, [@ratio] )

 

Is this always going to abide by the latest calendar year or the latest calendar year found in a conditional data set? 

 

In other words, if I add a slicer to select years/months, if I pick 2020  rather than 2021, will this query then see the filtered data ONLY, and therefore the MAXX year is now 2020 or is it still looking at the full data table which contains 2021 and therefore that's the year it's abiding by?

I figured it out. After all that, the formatting wasn't set to percentage. 

 

Thanks for your help!

Greg_Deckler
Community Champion
Community Champion

@AxlCox Sorry, having trouble following, can you post sample data as text and expected output?
Not really enough information to go on, please first check if your issue is a common issue listed here: https://community.powerbi.com/t5/Community-Blog/Before-You-Post-Read-This/ba-p/1116882

Also, please see this post regarding How to Get Your Question Answered Quickly: https://community.powerbi.com/t5/Community-Blog/How-to-Get-Your-Question-Answered-Quickly/ba-p/38490

The most important parts are:
1. Sample data as text, use the table tool in the editing bar
2. Expected output from sample data
3. Explanation in words of how to get from 1. to 2.



Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
DAX For Humans

DAX is easy, CALCULATE makes DAX hard...

Helpful resources

Announcements
August Power BI Update Carousel

Power BI Monthly Update - August 2025

Check out the August 2025 Power BI update to learn about new features.

August 2025 community update carousel

Fabric Community Update - August 2025

Find out what's new and trending in the Fabric community.