The ultimate Fabric, Power BI, SQL, and AI community-led learning event. Save €200 with code FABCOMM.
Get registeredCompete to become Power BI Data Viz World Champion! First round ends August 18th. Get started.
I have the following table in Power BI, (few thousands records)
EpiDates
I need to create DAX measure – [Active Clients], which will calculate the unique numbers of clients - [ClientID], for the clients, where [DischDate] = 12/31/2050.
For that, I have the following DAX code:
CALCULATE (DISTINCTCOUNT (EpiDates'[ClientID] ),
EpiDates'[DischDate]= DATE(2050, 12, 31))
But, when I create a Matrix in Power BI, I receive the following:
My [Active Clients] measure counts [ClientID]s for each [Period] used as grouped column.
While my goal is to create Matrix, where my measure will count [ClientID]s FOR THE HIGHEST [Period] VALUEs , for each ClientID,
as following:
Period 1 is the highest for the ClientID = 444 (1 Active Client counted)
Period 3 is the highest for the ClientIDs 333, 222 (2 Active Clients counted)
Period 2 is the highest for the ClientID = 555, but [DischDate] is not 12/31/2050 (not counted)
Period 0 has no ClientIDs for which this Period is the highest (no ClientIDs counted)
Please HELP – if it’s possible to update my existing measure to work the way described above
@Hell-1931 Try:
Active Clients 2 =
VAR __Period = MAX( 'EpiDates'[Period] )
VAR __Table =
SUMMARIZE(
FILTER( 'EpiDates', [DischDate] = DATE(2050, 12, 31) ),
[Client ID],
"__MaxPeriod", MAX( 'EpiDates'[Period])
)
VAR __Result = COUNTROWS( FILTER( __Table, [__MaxPeriod] = __Period ) )
RETURN
__Result
Greg_Deckler
It's closer to my goal when I modify your code as the following
Active Clients 2 =
VAR __Period = CALCULATE (
MAX ( 'EpiDates' [Period] ),
ALLEXCEPT (
' EpiDates ',
' EpiDates '[Client ID],
' EpiDates '[AdmDate],
' EpiDates '[LOS]
)
)
VAR __Table =
SUMMARIZE(
FILTER( 'EpiDates', [DischDate] = DATE(2050, 12, 31) ),
[Client ID],
"__MaxPeriod", MAX( 'EpiDates'[Period])
)
VAR __Result = COUNTROWS( FILTER( __Table, [__MaxPeriod] = __Period ) )
RETURN
__Result
After I modified __Period (filtered by AdmDate and LOS, besides Client ID)
If I show my data in "Table" PBI format, not in "Matrix", then it performs correct - counts ONLY the highest [Period] value
(see example, I have different original columns names, but it's the same calculation - highlighted in blue)
But, unfortunately, when I display this Measure in Matrix, it shows as empty
Your version - shows data, but, still ... counts Client IDs - for ALL the Period values, not for the HIGHEST Period value ...