Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

DAX - Last Value

Tags:

powerpivot

dax

I have this table

enter image description here

I would like to create measurement get the last traded value for each day. E.g.

enter image description here

How the DAX query should look like?

like image 595
user4815740 Avatar asked Nov 25 '16 03:11

user4815740


People also ask

What is Lastdate in DAX?

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.

What is TOPN in DAX?

TOPN is a function in DAX that gives you the ability to select the top items from a table based on an expression.

What does Maxx do in DAX?

Evaluates an expression for each row of a table and returns the largest value.


2 Answers

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.

like image 166
alejandro zuleta Avatar answered Sep 21 '22 08:09

alejandro zuleta


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]
    )
like image 44
Jason Wang Avatar answered Sep 20 '22 08:09

Jason Wang