Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Don't miss out! 2025 Microsoft Fabric Community Conference, March 31 - April 2, Las Vegas, Nevada. Use code MSCUST for a $150 discount. Prices go up February 11th. Register now.

Reply
IssieWissie
Frequent Visitor

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 price and serial code associated with them. Purchases can be months in advance. So whenever I want to evaluate a price of a part for this month, the last transaction could have been 3 months ago:

 

1. Measure finding the last transaction

 

 

Average = CALCULATE(AVERAGE(Purchasing2[Unit Price]),'Calendar Table'[Date]=MAX(Purchasing2[InvoiceDate]))

 

 

2. Measure evaluating the sum of all the serial codes

 

 

Cost = SUMX(SUMMARIZE(Purchasing2,Purchasing2[Code],"Price",[Average]),[Price])

 

 

 

With a couple filters I can get the correct card:

IssieWissie_0-1662549598826.png

 

But now I'd like to make a graph of this that evaluates each month. A sample:

CodeInvoiceDateUnit Price
066305/08/20221200
066317/08/20221300
213311/08/20222100
227312/08/20221300
165021/08/2022600
066303/09/20221500
213307/09/20222200

Answers would be:

DateCost
August5300
September5600

 

 

1 ACCEPTED SOLUTION
v-jingzhang
Community Support
Community Support

Hi @IssieWissie 

 

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. 

vjingzhang_0-1662700389834.png

 

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] )

 

vjingzhang_1-1662700644333.png

 

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.

View solution in original post

3 REPLIES 3
v-jingzhang
Community Support
Community Support

Hi @IssieWissie 

 

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. 

vjingzhang_0-1662700389834.png

 

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] )

 

vjingzhang_1-1662700644333.png

 

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.

Thanks a bunch, that works 

IssieWissie
Frequent Visitor

Quick update for anyone that has a similar situation. I have been able to get what I need, it unfortunately had to be a calculated column. If anyone still has a suggestion for a measure with the same product I'd appreciate it:

 

Average = CALCULATE(AVERAGE(Purchasing2[Price GBP]),'Calendar Table'[Date]=MAX(Purchasing2[InvoiceCreditDate]))

 

Cost = 
CALCULATE (
    SUMX (
        SUMMARIZE ( Purchasing2, Purchasing2[Code], "price", [Average] ),
        [price]
    ),
    DATESBETWEEN (
        'Calendar Table'[Date],
        DATE ( YEAR ( 'Calendar Table'[Date] ) - 1, MONTH ( 'Calendar Table'[Date] ), DAY ( 'Calendar Table'[Date] ) ),
        'Calendar Table'[Date]
    ),
    Purchasing2[Code] = "0663"
        || Purchasing2[Code] = "2133"
        || Purchasing2[Code] = "2273"
        || Purchasing2[Code] = "0861"
        || Purchasing2[Code] = "1650"
        || Purchasing2[Code] = "3727"
        || Purchasing2[Code] = "1980"
        || Purchasing2[Code] = "1349"
        || Purchasing2[Code] = "1200"
        || Purchasing2[Code] = "0893"
        || Purchasing2[Code] = "2670"
)

 

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

Jan25PBI_Carousel

Power BI Monthly Update - January 2025

Check out the January 2025 Power BI update to learn about new features in Reporting, Modeling, and Data Connectivity.

Jan NL Carousel

Fabric Community Update - January 2025

Find out what's new and trending in the Fabric community.