+ Reply to Thread
Results 1 to 4 of 4

Problem in Dax to create measure to find last cost by date

  1. #1
    Registered User
    Join Date
    06-02-2017
    Location
    Lahore
    MS-Off Ver
    2010
    Posts
    22

    Unhappy Problem in Dax to create measure to find last cost by date

    I need help on Dax to create measure to find last value by date.
    I have
    1-a data table
    2-a Unique names Table
    and
    3-the calendar table is in Data model.
    Relationship is created in data model between
    1-Date field in Data Table and Calendar
    2-between Names field in Names table and Data Table.
    I need to create a date-wise pivot table with quantity and cost fields in which i need the last cost value for null quantity / cost dates.
    I have created one measure
    =CALCULATE(Query1[Sum of Cost], LASTDATE('Calendar'[Date]))
    but not working for blank quantity dates.
    I have created another measure with dax
    =IF ( HASONEVALUE ( Query2[Name] ), VAR vItem = VALUES (Query2[Name]) VAR vLastDate = MAX ( 'Calendar'[Date] ) RETURN CALCULATE( Max ( Query1[Cost] ), 'Calendar'[Date] <= vLastDate ))
    but it is showing last maximum value instead of last latest value by date.
    Attached Files Attached Files

  2. #2
    Forum Expert XOR LX's Avatar
    Join Date
    04-18-2013
    Location
    Turin, Italy
    MS-Off Ver
    Office 365
    Posts
    7,742

    Re: Problem in Dax to create measure to find last cost by date

    Hi,

    PHP Code: 
    Last Cost Measure :=
    VAR 
    ThisDate =
        
    MIN'Calendar'[Date] )
    VAR 
    LastDateWithValue =
        
    CALCULATE(
            
    MAX'Calendar'[Date] ),
            
    FILTER(
                
    ALLSELECTEDQuery1 ),
                
    Query1[Date] <= ThisDate
                    
    && NOT ISBLANKQuery1[Cost] ) )
            )
        )
    RETURN
        
    CALCULATEMAXQuery1[Cost] ), 'Calendar'[Date] = LastDateWithValue 
    Regards
    Click * below if this answer helped

    Advanced Excel Techniques: http://excelxor.com/

  3. #3
    Registered User
    Join Date
    06-02-2017
    Location
    Lahore
    MS-Off Ver
    2010
    Posts
    22

    Re: Problem in Dax to create measure to find last cost by date

    Dear XOR LX, thanks It is working. Wonder full.
    Can you please help little more. I also need to find previous day cost. Means Last date minus 1. Please share the dax for that measure too.

  4. #4
    Forum Expert XOR LX's Avatar
    Join Date
    04-18-2013
    Location
    Turin, Italy
    MS-Off Ver
    Office 365
    Posts
    7,742

    Re: Problem in Dax to create measure to find last cost by date

    If you can re-post your file with the expected results for this new requirement then I'll gladly help.

    Regards

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Replies: 1
    Last Post: 11-17-2021, 12:42 PM
  2. Problem with CONCATENATEX measure in pivot table
    By Jayjay33 in forum Excel Charting & Pivots
    Replies: 6
    Last Post: 03-17-2021, 08:24 PM
  3. Pivot Table: Grand Total different measure from Column measure
    By chinneywow in forum Excel Charting & Pivots
    Replies: 0
    Last Post: 08-07-2019, 06:22 AM
  4. [SOLVED] FIND PRICE COST from MAX DATE based on ITEM ID and SALE DATE
    By aetedford in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 01-18-2018, 11:29 AM
  5. [SOLVED] Create a measure in Power Pivot to divide by value in subtotal row of the PP
    By rv02 in forum Excel Charting & Pivots
    Replies: 0
    Last Post: 04-22-2015, 11:22 AM
  6. find max $ of an item, same units of measure only
    By nxh145 in forum Excel General
    Replies: 1
    Last Post: 12-30-2011, 03:01 PM
  7. Replies: 1
    Last Post: 06-19-2006, 03:25 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1