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

Grow your Fabric skills and prepare for the DP-600 certification exam by completing the latest Microsoft Fabric 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
RTI Forums Carousel3

New forum boards available in Real-Time Intelligence.

Ask questions in Eventhouse and KQL, Eventstream, and Reflex.

MayPowerBICarousel1

Power BI Monthly Update - May 2024

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