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

Earn a 50% discount on the DP-600 certification exam by completing the Fabric 30 Days to Learn It challenge.

Reply
pierreemma
New Member

Dax measure to keep one row per employee with the most recent date

This is my table :

pierreemma_0-1699889999785.png

 

I need to calculate the number of ids declined by value_bet, keeping only the value corresponding to the most recent row (i.e. the min of rank_bet for each employee).

 

I've tried using this expression

 

 

CALCULATE(DISTINCTCOUNT(bet[id]), bet[rank_bet]= MINX(FILTER(bet, bet[id] = LASTNONBLANK(bet[id], bet[id])), bet[rank_bet]))

 

 

but the calculation of Min(rank_bet) is wrong when I break it down by value_bet: I get the impression that my measure takes the Min(rank_bet) by value_bet group and not grouped by id.

Example of expected result : 

  • without date filter :

pierreemma_2-1699890733274.png

  • with date filter : from 27/10/2021 to 08/12/2022 : 

pierreemma_3-1699890950120.png

 

 

 

 

1 ACCEPTED SOLUTION
AlexisOlson
Super User
Super User

I'm not sure why this filter is needed for a distinct count of id calculation but I'd approach it like this:

VAR _MinRanks_ =
    SUMMARIZE (
        bet,
        bet[id],
        "MinRank", MIN ( bet[rank_bet] )
    )
RETURN
    CALCULATE (
        DISTINCTCOUNT ( bet[id] ),
        TREATAS (
            _MinRanks_,
            bet[id],
            bet[rank_bet]
        )
    )

View solution in original post

2 REPLIES 2
AlexisOlson
Super User
Super User

I'm not sure why this filter is needed for a distinct count of id calculation but I'd approach it like this:

VAR _MinRanks_ =
    SUMMARIZE (
        bet,
        bet[id],
        "MinRank", MIN ( bet[rank_bet] )
    )
RETURN
    CALCULATE (
        DISTINCTCOUNT ( bet[id] ),
        TREATAS (
            _MinRanks_,
            bet[id],
            bet[rank_bet]
        )
    )

thank you, it works perfectly!

Helpful resources

Announcements
LearnSurvey

Fabric certifications survey

Certification feedback opportunity for the community.

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

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

April Fabric Community Update

Fabric Community Update - April 2024

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