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

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.

Reply
Brij
Helper III
Helper III

How to get the latest value within a given date range from another column?

Hi,

I'm trying to solve a scenario where I can return a maximum value (based on 'end date') from another column that has an outcome. See the below example;

 

IDEnd TimeOutcome
SUB0016/10/2022 13:23Approved
SUB00129/09/2022 15:24Reassign
SUB00216/09/2022 11:18Approved
SUB00212/09/2022 16:33Suspended
SUB0029/09/2022 11:25Suspended

 

In the above scenario, I have two IDs - SUB001 and SUB002. 

Ask - When I pick date period from 1st September 2022 to 30th September 2022 I should get total ID count 2,

1 under 'Approved' and 1 under 'Reassign' as for SUB002 all outcome falls in the same period as I have given here so it picks up the latest outcome and only that ID is counted. Whereas with SUB001, there are two oucome but the latest outcome is falling outside of my given period, that leaves only one record for the given period hence it is counted 1 under 'Reassign'

 

If I pick period from 25th September to 10th October in the above data table then it should return total ID count 1 under ' Approved' as both outcome from SUB001 falling within this period but it needs to pick up only the latest one that is end time = 6/10/2022 13:23 and none of the outcome from SUB002 falling with this date range!

 

I hope I have clearly explained what I am looking for. 

 

If someone can help me out would be great.

 

Thank you in advance.

Brij 

3 REPLIES 3
v-jialluo-msft
Community Support
Community Support

Hi Brij ,

 

Please follow these steps:

1.Create a measure to count the number of up-to-date states of all IDs

count =

VAR __ID =
    MAX ( 'Table'[id] )
VAR __TABLE =
    FILTER ( ALLSELECTED ( 'Table' ), 'Table'[id] = __ID )
VAR __MAX_TIME =
    MAXX ( __TABLE, 'Table'[EndTime] )
VAR __OUTCOME =
    MAXX (
        FILTER ( __TABLE, 'Table'[id] = __ID && 'Table'[EndTime] = __MAX_TIME ),
        'Table'[Outcome]
    )
VAR __COUNT =
    SUMX (
        FILTER (
            'Table',
            'Table'[id] = __ID
                && 'Table'[EndTime] = __MAX_TIME
                && 'Table'[Outcome] = __OUTCOME
        ),
        DISTINCTCOUNT ( 'Table'[id] )
    )
RETURN

    __COUNT

2.Final output

vjialluomsft_0-1666941848679.png

 

vjialluomsft_1-1666941848684.png

 

 

vjialluomsft_2-1666941848686.png

 

If your Current Period does not refer to this, please clarify in a follow-up reply.

 

Best Regards,

Gallen Luo

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

 

amitchandak
Super User
Super User

@Brij , refer if my blog on a similar topic can help

 

https://amitchandak.medium.com/power-bi-get-the-last-latest-value-of-a-category-d0cf2fcf92d0

https://amitchandak.medium.com/power-bi-get-the-sum-of-the-last-latest-value-of-a-category-f1c839ee8...

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

Hi @amitchandak 

Thanks for your quick response.

 

I have tried your solution and I think it's very close to what I am looking for but it is not quite there what I am looking for!

 

I guess I was not clear enough on my problem statement.

 

What I need is to get the count of all IDs for the latest outcome for a given period. The requirement is to provide volume  (count of IDs) for each latest outcome for the selected date range.

 

 

Helpful resources

Announcements
July 2025 community update carousel

Fabric Community Update - July 2025

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

July PBI25 Carousel

Power BI Monthly Update - July 2025

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