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
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
Solved! Go to Solution.
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:
Thanks for the reply from @mark_endicott , please allow me to provide another insight
Hi @GTaylor1959 ,
I created some data:
Column table:
vwCoronaryCareAdmission table:
Here are the steps you can follow:
1. Create calculated column.
Column_dax =
DATEDIFF(RELATED('column'[DateTimeOfReferral]),'vwCoronaryCareAdmission'[DateTimeOfAdmission],
DAY)
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:
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
Thanks for the reply from @mark_endicott , please allow me to provide another insight
Hi @GTaylor1959 ,
I created some data:
Column table:
vwCoronaryCareAdmission table:
Here are the steps you can follow:
1. Create calculated column.
Column_dax =
DATEDIFF(RELATED('column'[DateTimeOfReferral]),'vwCoronaryCareAdmission'[DateTimeOfAdmission],
DAY)
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:
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
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:
Check out the October 2024 Power BI update to learn about new features.
Learn from experts, get hands-on experience, and win awesome prizes.
User | Count |
---|---|
33 | |
16 | |
13 | |
10 | |
8 |
User | Count |
---|---|
58 | |
19 | |
12 | |
11 | |
10 |