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

Get certified in Microsoft Fabric—for free! For a limited time, the Microsoft Fabric Community team will be offering free DP-600 exam vouchers. Prepare 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
OCT PBI Update Carousel

Power BI Monthly Update - October 2024

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

September Hackathon Carousel

Microsoft Fabric & AI Learning Hackathon

Learn from experts, get hands-on experience, and win awesome prizes.

October NL Carousel

Fabric Community Update - October 2024

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