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

Find everything you need to get certified on Fabric—skills challenges, live sessions, exam prep, role guidance, and more. Get started

Reply
GTaylor1959
Regular Visitor

Percentage from a calculated measure if less than

Can anyone help please as  I am new to PowerBI.  I have tried many times to create a measure that will give me a percentage if my calculated measure below shows the time to admission from referral is less than 3 days.  I would like to show the visual as a percentage on a card.  My filter for dates will be within the last 7 days.  

 

The column dax is

'reporting vwCoronaryCareAdmission'[DateTimeOfAdmission] - RELATED('column'[DateTimeOfReferral])
Thank you!
 
 
2 ACCEPTED SOLUTIONS
mark_endicott
Solution Supplier
Solution Supplier

@GTaylor1959 

 

Not a great deal to go on here, but assuming you want a % that fall within 3 days you can use the DAX below:

 

% within 3 days = 

VAR _count = COUNTROWS( 'Table' )
VAR _count_in_3days = COUNTROWS(CALCULATETABLE( 'Table', 'Table'[days] <= 3))
VAR calc = DIVIDE( _count_in_3days, _count, 0 )
RETURN
    calc

 

Here I am using CALCULATETABLE to create a virtual table in the measure which stores only the rows where the days are less than or equal to 3. (you can change this filter as required). 

 

If you've not used them before VAR creates varaibles that store elements of your calculation for referencing back to later. 

 

A screenshot of this output is below: 

 

mark_endicott_0-1715849487701.png

 

View solution in original post

v-yangliu-msft
Community Support
Community Support

Thanks for the reply from @mark_endicott , please allow me to provide another insight
Hi  @GTaylor1959 ,

I created some data:

Column table:

vyangliumsft_0-1716193657230.png

vwCoronaryCareAdmission table:

vyangliumsft_0-1716193834982.png

 

Here are the steps you can follow:

1. Create calculated column.

 

Column_dax =
DATEDIFF(RELATED('column'[DateTimeOfReferral]),'vwCoronaryCareAdmission'[DateTimeOfAdmission],
DAY)

 

vyangliumsft_2-1716193691026.png

2. Create measure.

 

Measure =
var _count3=
COUNTX(
    FILTER(ALLSELECTED('vwCoronaryCareAdmission'),
    'vwCoronaryCareAdmission'[Column_dax]<=3),[Index])
var _allcount=
COUNTX(
    ALLSELECTED('vwCoronaryCareAdmission'),[Index])
return
DIVIDE(
    _count3,_allcount)

 

3. Result:

vyangliumsft_3-1716193691027.png

 

Best Regards,

Liu Yang

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly

 

 

View solution in original post

2 REPLIES 2
v-yangliu-msft
Community Support
Community Support

Thanks for the reply from @mark_endicott , please allow me to provide another insight
Hi  @GTaylor1959 ,

I created some data:

Column table:

vyangliumsft_0-1716193657230.png

vwCoronaryCareAdmission table:

vyangliumsft_0-1716193834982.png

 

Here are the steps you can follow:

1. Create calculated column.

 

Column_dax =
DATEDIFF(RELATED('column'[DateTimeOfReferral]),'vwCoronaryCareAdmission'[DateTimeOfAdmission],
DAY)

 

vyangliumsft_2-1716193691026.png

2. Create measure.

 

Measure =
var _count3=
COUNTX(
    FILTER(ALLSELECTED('vwCoronaryCareAdmission'),
    'vwCoronaryCareAdmission'[Column_dax]<=3),[Index])
var _allcount=
COUNTX(
    ALLSELECTED('vwCoronaryCareAdmission'),[Index])
return
DIVIDE(
    _count3,_allcount)

 

3. Result:

vyangliumsft_3-1716193691027.png

 

Best Regards,

Liu Yang

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly

 

 

mark_endicott
Solution Supplier
Solution Supplier

@GTaylor1959 

 

Not a great deal to go on here, but assuming you want a % that fall within 3 days you can use the DAX below:

 

% within 3 days = 

VAR _count = COUNTROWS( 'Table' )
VAR _count_in_3days = COUNTROWS(CALCULATETABLE( 'Table', 'Table'[days] <= 3))
VAR calc = DIVIDE( _count_in_3days, _count, 0 )
RETURN
    calc

 

Here I am using CALCULATETABLE to create a virtual table in the measure which stores only the rows where the days are less than or equal to 3. (you can change this filter as required). 

 

If you've not used them before VAR creates varaibles that store elements of your calculation for referencing back to later. 

 

A screenshot of this output is below: 

 

mark_endicott_0-1715849487701.png

 

Helpful resources

Announcements
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.

Power BI Carousel June 2024

Power BI Monthly Update - June 2024

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

PBI_Carousel_NL_June

Fabric Community Update - June 2024

Get the latest Fabric updates from Build 2024, key Skills Challenge voucher deadlines, top blogs, forum posts, and product ideas.