Forum Discussion
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:
| strname | datstamp | fltvalue |
| C1B | 7/27/2023 0:01 | 1 |
| C1B | 7/27/2023 0:02 | 5 |
| C1B | 7/27/2023 0:03 | 6 |
| C1B | 7/27/2023 0:04 | 4 |
| C1B | 7/27/2023 0:05 | 2 |
| C2B | 7/27/2023 0:01 | 1 |
| C2B | 7/27/2023 0:02 | 4 |
| C2B | 7/27/2023 0:03 | 5 |
| C2B | 7/27/2023 0:04 | 9 |
| C2B | 7/27/2023 0:05 | 2 |
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?
- LATEST=VAR last_value = MAX(Data[datstamp])VAR tag = "C2A"ReturnMAXX(FILTER(ALL(Data),Data[datstamp]=last_value &&Data[strname]=tag),Data[fltvalue])
7 Replies
- bv2023New Member
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!
- bv2023New 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.
- bv2023New MemberLATEST=VAR last_value = MAX(Data[datstamp])VAR tag = "C2A"ReturnMAXX(FILTER(ALL(Data),Data[datstamp]=last_value &&Data[strname]=tag),Data[fltvalue])