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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
Ericshepdawg
Frequent Visitor

Line graph to show current year with prior year comparison (only current year on x axis)

Hi all, I'm hoping to get some help with structuring a line graph. I would like to have the graph's x axis show all of the current year, and the values associated up until this month, then another line showing the previous year's comparison, but keeping the x axis only for the current year. So it would look like the following:

 

Screenshot 2023-08-22 at 9.19.57 AM.png

 

I've been trying to acheive this with another graph but I can't seem to get it to work. Attached below are the measures i'm using and screenshot of current graph.

 

Screenshot 2023-08-22 at 9.16.00 AM.png

 

Average TII =
AVERAGEX(
    VALUES(_Fact_AR[InvoiceDate]),  // Contextual iteration over unique InvoiceDates in the chart
    VAR FirstDayOfInvoiceMonth = DATE(YEAR(_Fact_AR[InvoiceDate]), MONTH(_Fact_AR[InvoiceDate]), 1)
    VAR RelatedDate = LOOKUPVALUE(_MasterDates[Adjusted First Business Day], _MasterDates[Date], FirstDayOfInvoiceMonth)
    RETURN
    IF(
        SELECTEDVALUE(_MasterDates[IsOnlyCurrentYear]) = 1 &&
        YEAR(_Fact_AR[InvoiceDate]) = YEAR(TODAY()),  // Add the condition for current year
        DATEDIFF(RelatedDate, _Fact_AR[InvoiceDate], DAY),
        BLANK()
    )
)
-------------------------------
 
Average TII Prior Year =
VAR CurrentYear = MAX(_MasterDates_Disconnected[Year])
RETURN
AVERAGEX(
    VALUES(_Fact_AR[InvoiceDate]),  // Contextual iteration over unique InvoiceDates in the chart
    IF(
        SELECTEDVALUE(_MasterDates[IsOnlyPriorYear]) = 1 &&
        YEAR(_Fact_AR[InvoiceDate]) = YEAR(TODAY()) - 1,  // Add the condition for prior year
        VAR FirstDayOfInvoiceMonth = DATE(YEAR(_Fact_AR[InvoiceDate]), MONTH(_Fact_AR[InvoiceDate]), 1)
        VAR RelatedDate = LOOKUPVALUE(_MasterDates[Adjusted First Business Day], _MasterDates[Date], FirstDayOfInvoiceMonth)
        RETURN
        DATEDIFF(
            RelatedDate,
            _Fact_AR[InvoiceDate],
            DAY),
        BLANK()
    )
)
5 REPLIES 5
Syk
Super User
Super User

If you remove the year from your axis to just have months, your lines can indicate the year. Will that work for you?

Hi Syk. Unfortunatley I need it to look like the first graph i referenced. Month-Year for current year.

You need to use the calculate function to modify the filter context so you're previous year measure only looks at the previous year. I'm not sure what your data model looks like but if the data is correct in your current measure (just wrong visually), try to wrap the current measure in something like

calculate([Measure here],dateadd('DateTable'[Date],year,-1))

Hey Syk. I'm pretty sure it's doing that already. Referencing the PriorYear, and then reflected on the graph as 2022. My intention is to get those values to display on a 2023 timeline. Wonder if disconnected dates is what i'm supposed to look at?

Hi,

Share the download link of the PBI file.


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

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