Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
4 years ago
Solved

Graph using a measure which evaluates each date for previous dates

Hi All,   I have a measure which works for me in a card format with a relative date filter. However, I'm struggling to get this on a graph now. My data is purchasing transactions which have a unit ...
  • v-jingzhang's avatar
    4 years ago

    Hi Anonymous 

     

    Here is my solution with a measure. Firstly I add a Dim Code table to the model which has all distinct code values from Purchasing2. Relate it to Purchasing2 on Code columns. 

     

    Then use the following measure. 

     

    Measure2 = 
    VAR endDate =
        ENDOFMONTH ( 'Calendar Table'[Date] )
    VAR startDate =
        EDATE ( STARTOFMONTH ( 'Calendar Table'[Date] ), -12 )
    VAR table1 =
        SUMMARIZE (
            'Code Table',
            'Code Table'[Code],
            "price",
                AVERAGEX (
                    TOPN (
                        1,
                        FILTER (
                            ALL ( Purchasing2 ),
                            Purchasing2[Code] = 'Code Table'[Code]
                                && Purchasing2[InvoiceDate] >= startDate
                                && Purchasing2[InvoiceDate] <= endDate
                        ),
                        [InvoiceDate], DESC
                    ),
                    [Unit Price]
                )
        )
    RETURN
        SUMX ( table1, [price] )
    

     

     

    Hope this is helpful. Sample file has been attached at bottom.

     

    Best Regards,
    Community Support Team _ Jing
    If this post helps, please Accept it as Solution to help other members find it.