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

Be one of the first to start using Fabric Databases. View on-demand sessions with database experts and the Microsoft product team to learn just how easy it is to get started. Watch now

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
Super User
Super User

@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
Super User
Super User

@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
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

ArunFabCon

Microsoft Fabric Community Conference 2025

Arun Ulag shares exciting details about the Microsoft Fabric Conference 2025, which will be held in Las Vegas, NV.

December 2024

A Year in Review - December 2024

Find out what content was popular in the Fabric community during 2024.