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
NickzNickz
Helper IV
Helper IV

displaying data by category and latest date

Hi, 

I have the below table (new version) for my testing data. 

NickzNickz_0-1691934263067.png

How can I create a measure for a line chart to display the latest amount based on the category, date and month?

The reason why I need to filter by date and month is because there will be a month 13. Month 13 is an Audited Amount. 
From there, I will filter the data to the latest 3 years. Below is the measure that I used. If anyone has the simplified version, please do advise me.

Last 3 Years = 

VAR _currentyear = YEAR(TODAY())
VAR _previousyear = SELECTEDVALUE(test4_3years[Year])
RETURN
    SWITCH(
        TRUE(),
        _previousyear <= _currentyear -1 &&
        _previousyear >= _currentyear -3, 1,
        0
    )


Thank you.
Regards,

NickzNickz

 

1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi @NickzNickz ,

 

Try this measure.

Latest Amount = 
VAR LatestDate =
    CALCULATE (
        MAX ( TableName[Date] ),
        ALLEXCEPT ( TableName, TableName[Category] )
    )
var _13=CALCULATE(SUM('TableName'[Amount]),FILTER(ALL('TableName'),'TableName'[Date]=MAX('TableName'[Date]) && 'TableName'[Category]=MAX('TableName'[Category]) && 'TableName'[Month]=13))
var _amount=
    CALCULATE (
        SUM ( TableName[Amount] ),
        TableName[Date] = LatestDate
    )
return IF(_13 =BLANK(),_amount,_13)

vtangjiemsft_0-1692080944079.png

Best Regards,

Neeko Tang

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

View solution in original post

3 REPLIES 3
Anonymous
Not applicable

Hi @NickzNickz ,

 

According to your description, here are my steps you can follow as a solution.

(1) My test data is the same as yours.

(2) We can create a measure. 

Latest Amount = 
VAR LatestDate =
    CALCULATE (
        MAX ( TableName[Date] ),
        ALLEXCEPT ( TableName, TableName[Category] )
    )
RETURN
    CALCULATE (
        SUM ( TableName[Amount] ),
        TableName[Date] = LatestDate
    )
Last 3 Years = 

VAR _currentyear = YEAR(TODAY())
VAR _previousyear = SELECTEDVALUE(test4_3years[Year])
RETURN
        IF ( _previousyear <= _currentyear - 1 && _previousyear >= _currentyear - 3, 1, 0 )

(3) Then the result is as follows.

vtangjiemsft_0-1692065482188.png

 

If the above one can't help you get the desired result, please provide some sample data in your tables (exclude sensitive data) with Text format and your expected result with backend logic and special examples. It is better if you can share a simplified pbix file. Thank you.

 

Best Regards,

Neeko Tang

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

Hi @Anonymous ,

 

I have tested to view the result... 

NickzNickz_0-1692070204895.png

Based on the scenario, if the category has month 12 and month 13, the measure should pick up month 13 only or else month 12 ... 

 

Regards,

NickzNickz

 

Anonymous
Not applicable

Hi @NickzNickz ,

 

Try this measure.

Latest Amount = 
VAR LatestDate =
    CALCULATE (
        MAX ( TableName[Date] ),
        ALLEXCEPT ( TableName, TableName[Category] )
    )
var _13=CALCULATE(SUM('TableName'[Amount]),FILTER(ALL('TableName'),'TableName'[Date]=MAX('TableName'[Date]) && 'TableName'[Category]=MAX('TableName'[Category]) && 'TableName'[Month]=13))
var _amount=
    CALCULATE (
        SUM ( TableName[Amount] ),
        TableName[Date] = LatestDate
    )
return IF(_13 =BLANK(),_amount,_13)

vtangjiemsft_0-1692080944079.png

Best Regards,

Neeko Tang

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

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.