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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
bv2023
New Member

Return the latest value by date and condition

Hello,

 

I would like to have a PowerBI Card or Multi-row Card show the latest value from a table based on time and other conditions.

 

I have the following table from which I will be pulling information:

strnamedatstampfltvalue
C1B7/27/2023 0:011
C1B7/27/2023 0:025
C1B7/27/2023 0:036
C1B7/27/2023 0:044
C1B7/27/2023 0:052
C2B7/27/2023 0:011
C2B7/27/2023 0:024
C2B7/27/2023 0:035
C2B7/27/2023 0:049
C2B7/27/2023 0:052

 

I am having trouble coming up with a measure that will return fltvalue where the strname=C1B and the most recent date. Could someone help me with the DAX code that creates a measure that will pull the most recent ftvalue for just C1B?

 

1 ACCEPTED SOLUTION
bv2023
New Member

LATEST=

VAR last_value = MAX(Data[datstamp])
VAR tag = "C2A"

Return
MAXX(FILTER(ALL(Data),Data[datstamp]=last_value &&
Data[strname]=tag),
Data[fltvalue])

View solution in original post

7 REPLIES 7
bv2023
New Member

LATEST=

VAR last_value = MAX(Data[datstamp])
VAR tag = "C2A"

Return
MAXX(FILTER(ALL(Data),Data[datstamp]=last_value &&
Data[strname]=tag),
Data[fltvalue])
bv2023
New Member

In words, the code needs to look at the table column [datstamp] where the date is maximum, ensure [strname]= 'C1B' and pull the value at [fltvalue]. Can someone else assist with this challenge? I do not know the syntax well enough.

Arul
Super User
Super User

@bv2023 ,

Can you try this measure?

Max value Per Strname = 
CALCULATE (
    MAX ( 'Table'[fltvalue] ),
    INDEX (
        1,
        ALL ( 'Table'[datstamp], 'Table'[strname] ),
        ORDERBY ( 'Table'[datstamp], DESC ),
        DEFAULT,
        PARTITIONBY ( 'Table'[strname] )
    )
)




Did I answer your question? Mark my post as a solution!

Proud to be a Super User!


LinkedIn


The measure compiles but does not return ftvalue of 2 when inserted into a Card in PowerBI. How do I specify or filter to show only strname=C1B? 

Thanks for your help Arul!

@bv2023 ,

added one filter from strname, Can you try now?

 

Max value Per Strname = 
CALCULATE (
    MAX ( 'Table'[fltvalue] ),
    INDEX (
        1,
        ALL ( 'Table'[datstamp], 'Table'[strname] ),
        ORDERBY ( 'Table'[datstamp], DESC ),
        DEFAULT,
        PARTITIONBY ( 'Table'[strname] )
    ),'Table'[strname] = "C1B"
)

 





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!


LinkedIn


I am getting "Can't display the visual." due to 


The resultset of a query to external data source has exceeded the maximum allowed size of '1000000' rows.

 

Any workaround for this? 

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

December 2025 Power BI Update Carousel

Power BI Monthly Update - December 2025

Check out the December 2025 Power BI Holiday Recap!

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.