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

Get certified in Microsoft Fabric—for free! For a limited time, get a free DP-600 exam voucher to use by the end of 2024. Register now

Reply
inversia
Frequent Visitor

Last Record Value by Condition

Hi,

 

thank you for support.

 

To simplify, I have a fact Table A linked to the DATA Table.

 

DATACODTYPEAMOUNT
2024-11-20AF0
2024-11-20AG15
2024-10-02AF10
2024-10-03BG5
2024-10-01BF1

 

I would like to get only the last value (ALL TIME) with TYPE = F and AMOUNT > 0, independently from the date selected in the filter menu :

 

CODLAST VALUE
A10
B

1

TOTAL

11

 

Thank you so much,

Alessandro

1 ACCEPTED SOLUTION

Hi @dharmendars007 ,

thank you so much.

For each COD the value is correct, but the total is wrong, maybe it get the MAX 

have you other idea? 

 

It might be useful create a table like and then make SUM(LastValue) ?

DATACODTYPEAMOUNTLAST VALUE
2024-11-20AF0 
2024-11-20AG15 
2024-10-02AF1010
2024-10-03BG5 
2024-10-01BF11

View solution in original post

6 REPLIES 6
FreemanZ
Super User
Super User

hi @inversia ,

 

try like:

measure =

VAR _table =

ADDCOLUMNS(

   VALUES(data[COD]),

    "MinDate", CALCULATE(MIN(data[date])),

)

VAR _result =

CALCULATE(

    SUM(data[Amount]),

    TREATAS(

         _table,

         data[COD],

         data[date]

     ),

    data[TYPE]="F",

    data[amount]>0

)

RETURN _result

Thank you so much

dharmendars007
Solution Sage
Solution Sage

Hello @inversia , 

To calculate the "LAST VALUE" with the conditions specified (TYPE = F, AMOUNT > 0, independently of date filters), you can create a DAX measure in Power BI

LAST VALUE =
VAR LastDate =
CALCULATE( MAX('DATA'[DATA]),
FILTER(
ALL('DATA'), 'DATA'[TYPE] = "F" && 'DATA'[AMOUNT] > 0 && 'DATA'[COD] = MAX('DATA'[COD])))
VAR LastValue =
CALCULATE( MAX('DATA'[AMOUNT]),
FILTER( ALL('DATA'), 'DATA'[TYPE] = "F" && 'DATA'[AMOUNT] > 0 && 'DATA'[COD] = MAX('DATA'[COD]) &&
'DATA'[DATA] = LastDate))
RETURN
LastValue

This approach ensures that you retrieve the correct last value for each COD, even when the visual or report has date slicers applied

If you find this helpful , please mark it as solution which will be helpful for others and Your Kudos/Likes 👍 are much appreciated!

 

Thank You

Dharmendar S

LinkedIN 

 

 

Hi @dharmendars007 ,

thank you so much.

For each COD the value is correct, but the total is wrong, maybe it get the MAX 

have you other idea? 

 

It might be useful create a table like and then make SUM(LastValue) ?

DATACODTYPEAMOUNTLAST VALUE
2024-11-20AF0 
2024-11-20AG15 
2024-10-02AF1010
2024-10-03BG5 
2024-10-01BF11

Hello @inversia , 

To Display the Total: If you want to display the total of the "LAST VALUE" column (e.g., TOTAL 11), you can create another measure:

TOTAL LAST VALUE =
SUMX(VALUES('DATA'[COD]), [LAST VALUE])

If you find this helpful , please mark it as solution which will be helpful for others and Your Kudos/Likes are much appreciated!

 

Thank You

Dharmendar S

LinkedIN 





It's work. Awesome. Thank you so much

Helpful resources

Announcements
November Carousel

Fabric Community Update - November 2024

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

Live Sessions with Fabric DB

Be one of the first to start using Fabric Databases

Starting December 3, join live sessions with database experts and the Fabric product team to learn just how easy it is to get started.

Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount! Early Bird pricing ends December 9th.

Nov PBI Update Carousel

Power BI Monthly Update - November 2024

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

Top Solution Authors