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
letsgobro
Frequent Visitor

Counting unique clients by benefit only from their most recent record by date.

My goal seems simple but I have sunk a lot of hours into this already and am looking for help with the following:
I am trying to get a distinct count of clients and the different types of benefits they have.  The challenge here is that I only want to know based off the most recent time they were asked.

Here is a sample of a filtered fact table:

letsgobro_0-1736964723515.png

In a table visual I'd expect to have it so that we would see

Non cash benefit IdCount of Clients
72
102

 

Benefit IDs 1 and 5 are excluded as their is a more recent record (Assessment_Id) on file for that particular client.

Everything I have tried just doesn't quite get there for one reason or another even after trying to have AI tools help me out. 

I am open to suggestions on how best to figure this out.  I have to stick to DAX measures as this will be in a fabric model.

1 ACCEPTED SOLUTION
gmsamborn
Super User
Super User

Hi @letsgobro 

 

Would something like this help?

Measure = 
VAR _Client = MAX( 'FactTable'[Client_Id] )
VAR _Date = 
    CALCULATE(
        MAX( 'FactTable'[Date_Id] ),
        ALL( 'FactTable' ),
        'FactTable'[Client_Id] = _Client
    )
VAR _NC_Ben_List =
    DISTINCT(
        SELECTCOLUMNS(
            FILTER(
                'FactTable',
                [Client_Id] = _Client
                    && [Date_Id] = _Date
            ),
            [Non_Cash_Benefit_Id]
        )
    )
VAR _Result =
    CALCULATE(
        DISTINCTCOUNT( 'FactTable'[Client_Id] ),
        FILTER(
            ALL( 'FactTable' ),
            [Non_Cash_Benefit_Id] IN _NC_Ben_List
        )
    )
RETURN
    _Result

 

Let me know if you have any questions.

 

letsgobro.pbix

 



Proud to be a Super User!

daxformatter.com makes life EASIER!

View solution in original post

3 REPLIES 3
gmsamborn
Super User
Super User

Hi @letsgobro 

 

Would something like this help?

Measure = 
VAR _Client = MAX( 'FactTable'[Client_Id] )
VAR _Date = 
    CALCULATE(
        MAX( 'FactTable'[Date_Id] ),
        ALL( 'FactTable' ),
        'FactTable'[Client_Id] = _Client
    )
VAR _NC_Ben_List =
    DISTINCT(
        SELECTCOLUMNS(
            FILTER(
                'FactTable',
                [Client_Id] = _Client
                    && [Date_Id] = _Date
            ),
            [Non_Cash_Benefit_Id]
        )
    )
VAR _Result =
    CALCULATE(
        DISTINCTCOUNT( 'FactTable'[Client_Id] ),
        FILTER(
            ALL( 'FactTable' ),
            [Non_Cash_Benefit_Id] IN _NC_Ben_List
        )
    )
RETURN
    _Result

 

Let me know if you have any questions.

 

letsgobro.pbix

 



Proud to be a Super User!

daxformatter.com makes life EASIER!

Wow, that gets me 99% of the way there.
I was getting a little higher of a count on those benefit types but I altered the VAR _Result to use the ALLSELECTED filter as opposed to ALL. 
After setting that it seems to be spot on.

 

I kind of understand what each part is doing but I will probably need to research more so I can get a better grasp on how you accomplished this.

Was this the first approach that you thought of or did you try something else first that didn't work?

Thanks a lot!!!!

Hi @letsgobro 

 

I tried a couple times before I came up with the _NC_Ben_List variable to be able to use IN (in _Result).

I wasn't sure how it would work with real data since it was a pretty small dataset.

 

Glad it works.



Proud to be a Super User!

daxformatter.com makes life EASIER!

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.