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

Compete to become Power BI Data Viz World Champion! First round ends August 18th. Get started.

Reply
Hell-1931
Helper II
Helper II

Needed to update an existing DAX measure, to work in a specific way

I have the following table in Power BI, (few thousands records)

EpiDates 

 

EpiDates.jpg

 

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:

Matrix_Wrong.jpg

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:

Matrix_Correct.jpg

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

 

2 REPLIES 2
Greg_Deckler
Community Champion
Community Champion

@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


Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
DAX For Humans

DAX is easy, CALCULATE makes DAX hard...

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)

Capture.PNG

 

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

 

 

 

Helpful resources

Announcements
August Power BI Update Carousel

Power BI Monthly Update - August 2025

Check out the August 2025 Power BI update to learn about new features.

August 2025 community update carousel

Fabric Community Update - August 2025

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