I have this table
I would like to create measurement get the last traded value for each day. E.g.
How the DAX query should look like?
As DAX LASTDATE function returns a table that contains a single column and single value, it can be used as a parameter to any DAX function that requires a table in its parameters. Further, the returned value can be used wherever a date value is required.
TOPN is a function in DAX that gives you the ability to select the top items from a table based on an expression.
Evaluates an expression for each row of a table and returns the largest value.
You have to create two measures. One for the last time in each date and another to get the value for that date and time.
Last Time :=
CALCULATE(MAX([Time]),FILTER('Table',[Date]=MAX([Date])))
Last Traded Value =
CALCULATE (
MAX ( 'Table'[Traded Value] ),
FILTER ( 'Table', [Date] = MAX ( [Date] ) && [Last Time] = [Time] )
)
Then add Date
column to rows and Last Time
and Last Traded Value
measures to Values pane in a pivot table.
Let me know if this helps.
For example:
DEFINE
VAR TableTMP =
ADDCOLUMNS ( 'Table', "DateTime", [Date] + [Time] )
EVALUATE
SUMMARIZE (
NATURALINNERJOIN (
TableTMP,
SUMMARIZE (
GROUPBY ( TableTMP, [Date], "DateTime", MAXX ( CURRENTGROUP (), [DateTime] ) ),
[DateTime]
)
),
[Date],
[Time],
[Traded Value]
)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With