<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Previous  months data generated for line chart in DAX Commands and Tips</title>
    <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Previous-months-data-generated-for-line-chart/m-p/4351336#M172800</link>
    <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="javascript:void(0)" data-lia-user-mentions="" data-lia-user-uid="471932" data-lia-user-login="Puja_Kumari25" class="lia-mention lia-mention-user"&gt;Puja_Kumari25&lt;/a&gt;&amp;nbsp;&amp;nbsp;,&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;
&lt;P&gt;You only need to modify the first variable in the measure.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;VAR SelectedDate = CALCULATE(MAX('CalendarFY'[Date]),ALLSELECTED())&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;And the measure is as follows.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;ForYearSales = 
VAR SelectedDate = CALCULATE(MAX('CalendarFY'[Date]),ALLSELECTED())  -- Get the selected date from the slicer
VAR StartfYear = 
    IF(
        ISBLANK(SelectedDate),  -- Check if no date is selected
        DATE(YEAR(TODAY()), 1, 1),  -- If no date is selected, get the start of the current year (1st January)
        DATE(YEAR(SelectedDate), 1, 1)  -- If a date is selected, get the start of the selected year (1st January)
    )
VAR EndfYear = 
    IF(
        ISBLANK(SelectedDate),  -- Check if no date is selected
        TODAY(),  -- If no date is selected, use today's date as the end of the year
        SelectedDate  -- If date is selected, use the selected date as the end of the year
    )


VAR SalesInRange = 
    CALCULATE(
        [ActualSales],  -- Calculate the sales measure
        'CalendarFY'[Date] &amp;gt;= StartfYear &amp;amp;&amp;amp; 'CalendarFY'[Date] &amp;lt;= EndfYear   &amp;amp;&amp;amp; 'CalendarFY'[year] &amp;gt;=  YEAR(StartfYear) &amp;amp;&amp;amp; 'CalendarFY'[year] &amp;lt;=  YEAR(EndfYear)
    )
RETURN
    IF(ISBLANK(SalesInRange), 0, SalesInRange)  -- Return 0 if no sales data is found for the given period&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;The final result is as follows. The line chart will be a zero line for the month following the selected date.&lt;/P&gt;
&lt;P&gt;&lt;img /&gt;&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;Please see the attached pbix for reference.&lt;BR /&gt;&lt;BR /&gt;Best Regards,&lt;BR /&gt;Dengliang Li&lt;BR /&gt;&lt;BR /&gt;If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.&lt;/P&gt;</description>
    <pubDate>Mon, 06 Jan 2025 05:20:17 GMT</pubDate>
    <dc:creator>Anonymous</dc:creator>
    <dc:date>2025-01-06T05:20:17Z</dc:date>
    <item>
      <title>Previous  months data generated for line chart</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Previous-months-data-generated-for-line-chart/m-p/4348850#M172726</link>
      <description>&lt;P&gt;Hi&amp;nbsp; Team,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am using the below-mentioned dax for year-wise revenue calculation. Here we have a date table&amp;nbsp; which is used in date slicer where we hide min date to look like the calendar visual.&amp;nbsp; Users can select a date from the calendar, if no date is selected, the current date will be the max date.&lt;/P&gt;&lt;P&gt;We have generated a line chart for the year-wise sales. We have dropped only months from the date hierarchy.&amp;nbsp;&lt;/P&gt;&lt;P&gt;if we select a date , the line chart shows only data till the selected data or current date but it generates data for the other months.&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Please help me&amp;nbsp; our line chart will be a straight line for zero for the months that are after selected date.&amp;nbsp;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;ForYearSales =&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;VAR&lt;/SPAN&gt; &lt;SPAN&gt;SelectedDate&lt;/SPAN&gt;&lt;SPAN&gt; = &lt;/SPAN&gt;&lt;SPAN&gt;MAX&lt;/SPAN&gt;&lt;SPAN&gt;(&lt;/SPAN&gt;&lt;SPAN&gt;'CalendarFY'&lt;/SPAN&gt;&lt;SPAN&gt;[Date]&lt;/SPAN&gt;&lt;SPAN&gt;) &amp;nbsp;&lt;/SPAN&gt;&lt;SPAN&gt;-- Get the selected date from the slicer&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;VAR&lt;/SPAN&gt; &lt;SPAN&gt;StartfYear&lt;/SPAN&gt;&lt;SPAN&gt; = &lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &lt;/SPAN&gt;&lt;SPAN&gt;IF&lt;/SPAN&gt;&lt;SPAN&gt;(&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;/SPAN&gt;&lt;SPAN&gt;ISBLANK&lt;/SPAN&gt;&lt;SPAN&gt;(&lt;/SPAN&gt;&lt;SPAN&gt;SelectedDate&lt;/SPAN&gt;&lt;SPAN&gt;), &amp;nbsp;&lt;/SPAN&gt;&lt;SPAN&gt;-- Check if no date is selected&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;/SPAN&gt;&lt;SPAN&gt;DATE&lt;/SPAN&gt;&lt;SPAN&gt;(&lt;/SPAN&gt;&lt;SPAN&gt;YEAR&lt;/SPAN&gt;&lt;SPAN&gt;(&lt;/SPAN&gt;&lt;SPAN&gt;TODAY&lt;/SPAN&gt;&lt;SPAN&gt;()), &lt;/SPAN&gt;&lt;SPAN&gt;1&lt;/SPAN&gt;&lt;SPAN&gt;, &lt;/SPAN&gt;&lt;SPAN&gt;1&lt;/SPAN&gt;&lt;SPAN&gt;), &amp;nbsp;&lt;/SPAN&gt;&lt;SPAN&gt;-- If no date is selected, get the start of the current year (1st January)&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;/SPAN&gt;&lt;SPAN&gt;DATE&lt;/SPAN&gt;&lt;SPAN&gt;(&lt;/SPAN&gt;&lt;SPAN&gt;YEAR&lt;/SPAN&gt;&lt;SPAN&gt;(&lt;/SPAN&gt;&lt;SPAN&gt;SelectedDate&lt;/SPAN&gt;&lt;SPAN&gt;), &lt;/SPAN&gt;&lt;SPAN&gt;1&lt;/SPAN&gt;&lt;SPAN&gt;, &lt;/SPAN&gt;&lt;SPAN&gt;1&lt;/SPAN&gt;&lt;SPAN&gt;) &amp;nbsp;&lt;/SPAN&gt;&lt;SPAN&gt;-- If a date is selected, get the start of the selected year (1st January)&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; )&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;VAR&lt;/SPAN&gt; &lt;SPAN&gt;EndfYear&lt;/SPAN&gt;&lt;SPAN&gt; = &lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &lt;/SPAN&gt;&lt;SPAN&gt;IF&lt;/SPAN&gt;&lt;SPAN&gt;(&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;/SPAN&gt;&lt;SPAN&gt;ISBLANK&lt;/SPAN&gt;&lt;SPAN&gt;(&lt;/SPAN&gt;&lt;SPAN&gt;SelectedDate&lt;/SPAN&gt;&lt;SPAN&gt;), &amp;nbsp;&lt;/SPAN&gt;&lt;SPAN&gt;-- Check if no date is selected&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;/SPAN&gt;&lt;SPAN&gt;TODAY&lt;/SPAN&gt;&lt;SPAN&gt;(), &amp;nbsp;&lt;/SPAN&gt;&lt;SPAN&gt;-- If no date is selected, use today's date as the end of the year&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;/SPAN&gt;&lt;SPAN&gt;SelectedDate&lt;/SPAN&gt;&lt;SPAN&gt; &amp;nbsp;&lt;/SPAN&gt;&lt;SPAN&gt;-- If date is selected, use the selected date as the end of the year&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; )&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;VAR&lt;/SPAN&gt; &lt;SPAN&gt;SalesInRange&lt;/SPAN&gt;&lt;SPAN&gt; = &lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &lt;/SPAN&gt;&lt;SPAN&gt;CALCULATE&lt;/SPAN&gt;&lt;SPAN&gt;(&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;/SPAN&gt;&lt;SPAN&gt;[ActualSales]&lt;/SPAN&gt;&lt;SPAN&gt;, &amp;nbsp;&lt;/SPAN&gt;&lt;SPAN&gt;-- Calculate the sales measure&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;/SPAN&gt;&lt;SPAN&gt;'CalendarFY'&lt;/SPAN&gt;&lt;SPAN&gt;[Date]&lt;/SPAN&gt;&lt;SPAN&gt; &amp;gt;= &lt;/SPAN&gt;&lt;SPAN&gt;StartfYear&lt;/SPAN&gt;&lt;SPAN&gt; &amp;amp;&amp;amp; &lt;/SPAN&gt;&lt;SPAN&gt;'CalendarFY'&lt;/SPAN&gt;&lt;SPAN&gt;[Date]&lt;/SPAN&gt;&lt;SPAN&gt; &amp;lt;= &lt;/SPAN&gt;&lt;SPAN&gt;EndfYear&lt;/SPAN&gt;&lt;SPAN&gt; &amp;nbsp;&lt;/SPAN&gt;&lt;SPAN&gt;-- Filter for the selected year or current year&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; )&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;RETURN&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &lt;/SPAN&gt;&lt;SPAN&gt;IF&lt;/SPAN&gt;&lt;SPAN&gt;(&lt;/SPAN&gt;&lt;SPAN&gt;ISBLANK&lt;/SPAN&gt;&lt;SPAN&gt;(&lt;/SPAN&gt;&lt;SPAN&gt;SalesInRange&lt;/SPAN&gt;&lt;SPAN&gt;), &lt;/SPAN&gt;&lt;SPAN&gt;0&lt;/SPAN&gt;&lt;SPAN&gt;, &lt;/SPAN&gt;&lt;SPAN&gt;SalesInRange&lt;/SPAN&gt;&lt;SPAN&gt;) &amp;nbsp;&lt;/SPAN&gt;&lt;SPAN&gt;-- Return 0 if no sales data is found for the given period&lt;/SPAN&gt;&lt;/DIV&gt;&lt;/DIV&gt;</description>
      <pubDate>Thu, 02 Jan 2025 19:15:28 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Previous-months-data-generated-for-line-chart/m-p/4348850#M172726</guid>
      <dc:creator>Puja_Kumari25</dc:creator>
      <dc:date>2025-01-02T19:15:28Z</dc:date>
    </item>
    <item>
      <title>Re: Previous  months data generated for line chart</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Previous-months-data-generated-for-line-chart/m-p/4349164#M172734</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="javascript:void(0)" data-lia-user-mentions="" data-lia-user-uid="471932" data-lia-user-login="Puja_Kumari25" class="lia-mention lia-mention-user"&gt;Puja_Kumari25&lt;/a&gt;&amp;nbsp;,&lt;BR /&gt;&lt;BR /&gt;I'm not sure how your dataset is designed, here is my sample.&lt;/P&gt;
&lt;P&gt;Creates a disconnected calendar table with date fields derived from the dates of the data table.&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;Calendar = CALENDAR(MIN('Table'[Date]),MAX('Table'[Date]))&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;img /&gt;&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;The measure is as follows.&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;ForYearSales = 
VAR SelectedDate = SELECTEDVALUE('Calendar'[Date])  -- Get the selected date from the slicer
VAR StartfYear =
    IF(
        ISBLANK(SelectedDate),  -- Check if no date is selected
        DATE(YEAR(TODAY()), 1, 1),  -- If no date is selected, get the start of the current year (1st January)
        DATE(YEAR(SelectedDate), 1, 1)  -- If a date is selected, get the start of the selected year (1st January)
    )
VAR EndfYear =
    IF(
        ISBLANK(SelectedDate),  -- Check if no date is selected
        TODAY(),  -- If no date is selected, use today's date as the end of the year
        SelectedDate  -- If date is selected, use the selected date as the end of the year
    )
VAR SalesInRange =
    CALCULATE(
        [ActualSales],  -- Calculate the sales measure
       KEEPFILTERS('Table'[Date] &amp;gt;= StartfYear &amp;amp;&amp;amp; 'Table'[Date] &amp;lt;= EndfYear)  -- Filter for the selected year or current year
    )

RETURN
    IF(ISBLANK(SelectedDate), --If no date is selected
    IF(
        MAX('Table'[Date])&amp;lt;StartfYear,BLANK(), -- Dates less than the current year are blank.
        IF(ISBLANK(SalesInRange),0,SalesInRange) -- Returns 0 if no sales data was found for the given period
    ), 
    IF(ISBLANK(SalesInRange),0,SalesInRange) -- Return 0 if no sales data is found for the given period
)&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Results when a date is selected from the calendar.&lt;/P&gt;
&lt;P&gt;&lt;img /&gt;&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;Result of not selecting a calendar date.&lt;/P&gt;
&lt;P&gt;&lt;img /&gt;&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;Please see the attached pbix for reference.&lt;BR /&gt;&lt;BR /&gt;Best Regards,&lt;BR /&gt;Dengliang Li&lt;BR /&gt;&lt;BR /&gt;If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 03 Jan 2025 03:12:53 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Previous-months-data-generated-for-line-chart/m-p/4349164#M172734</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2025-01-03T03:12:53Z</dc:date>
    </item>
    <item>
      <title>Re: Previous  months data generated for line chart</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Previous-months-data-generated-for-line-chart/m-p/4350300#M172766</link>
      <description>&lt;P&gt;We are dropping months on the axis. We need only a line chart for the selected date's year. here line chart is generating and data for previous all year's months&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;A title="sample pbi file" href="https://1drv.ms/u/s!AlYnX1B1MG4WdIbKL6hURhNLGZU?e=LXxiMo" target="_self"&gt;sample file&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 03 Jan 2025 21:43:48 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Previous-months-data-generated-for-line-chart/m-p/4350300#M172766</guid>
      <dc:creator>Puja_Kumari25</dc:creator>
      <dc:date>2025-01-03T21:43:48Z</dc:date>
    </item>
    <item>
      <title>Re: Previous  months data generated for line chart</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Previous-months-data-generated-for-line-chart/m-p/4350437#M172768</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="javascript:void(0)" data-lia-user-mentions="" data-lia-user-uid="471932" data-lia-user-login="Puja_Kumari25" class="lia-mention lia-mention-user"&gt;Puja_Kumari25&lt;/a&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Can you please try this:&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;ForYearSales =
VAR SelectedDate = MAX('CalendarFY'[Date])  -- Get the selected date from the slicer
VAR StartfYear =
    IF(
        ISBLANK(SelectedDate),  -- Check if no date is selected
        DATE(YEAR(TODAY()), 1, 1),  -- If no date is selected, get the start of the current year (1st January)
        DATE(YEAR(SelectedDate), 1, 1)  -- If a date is selected, get the start of the selected year (1st January)
    )
VAR EndfYear =
    IF(
        ISBLANK(SelectedDate),  -- Check if no date is selected
        TODAY(),  -- If no date is selected, use today's date as the end of the year
        SelectedDate  -- If a date is selected, use the selected date as the end of the year
    )
VAR IsInRange =
    MAX('CalendarFY'[Date]) &amp;lt;= EndfYear  -- Check if the current date in the context is within the selected range
VAR SalesInRange =
    CALCULATE(
        [ActualSales],  -- Calculate the sales measure
        'CalendarFY'[Date] &amp;gt;= StartfYear &amp;amp;&amp;amp; 'CalendarFY'[Date] &amp;lt;= EndfYear  -- Filter for the selected year or current year
    )
RETURN
    IF(IsInRange, SalesInRange, 0)  -- Show actual sales for dates in range, otherwise show 0&lt;/LI-CODE&gt;&lt;P&gt;Power BI's visuals respect the context of the data being displayed. By explicitly setting the value to zero for months outside the range, the line chart will draw a straight line at zero for these months.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Did I answer your question? Mark my post as a solution, this will help others!&lt;/STRONG&gt;&lt;BR /&gt;If my response(s) assisted you in any way, don't forget to drop me a "&lt;STRONG&gt;Kudos&lt;/STRONG&gt;" &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;&lt;P&gt;Kind Regards,&lt;BR /&gt;Poojara&lt;BR /&gt;Data Analyst | MSBI Developer | Power BI Consultant&lt;BR /&gt;&lt;STRONG&gt;Consider Subscribing my YouTube for Beginners/Advance Concepts:&lt;/STRONG&gt;&amp;nbsp;&lt;A href="https://youtube.com/@biconcepts?si=04iw9SYI2HN80HKS" target="_self"&gt;https://youtube.com/@biconcepts?si=04iw9SYI2HN80HKS&lt;/A&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 04 Jan 2025 04:43:42 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Previous-months-data-generated-for-line-chart/m-p/4350437#M172768</guid>
      <dc:creator>Poojara_D12</dc:creator>
      <dc:date>2025-01-04T04:43:42Z</dc:date>
    </item>
    <item>
      <title>Re: Previous  months data generated for line chart</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Previous-months-data-generated-for-line-chart/m-p/4351336#M172800</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="javascript:void(0)" data-lia-user-mentions="" data-lia-user-uid="471932" data-lia-user-login="Puja_Kumari25" class="lia-mention lia-mention-user"&gt;Puja_Kumari25&lt;/a&gt;&amp;nbsp;&amp;nbsp;,&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;
&lt;P&gt;You only need to modify the first variable in the measure.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;VAR SelectedDate = CALCULATE(MAX('CalendarFY'[Date]),ALLSELECTED())&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;And the measure is as follows.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;ForYearSales = 
VAR SelectedDate = CALCULATE(MAX('CalendarFY'[Date]),ALLSELECTED())  -- Get the selected date from the slicer
VAR StartfYear = 
    IF(
        ISBLANK(SelectedDate),  -- Check if no date is selected
        DATE(YEAR(TODAY()), 1, 1),  -- If no date is selected, get the start of the current year (1st January)
        DATE(YEAR(SelectedDate), 1, 1)  -- If a date is selected, get the start of the selected year (1st January)
    )
VAR EndfYear = 
    IF(
        ISBLANK(SelectedDate),  -- Check if no date is selected
        TODAY(),  -- If no date is selected, use today's date as the end of the year
        SelectedDate  -- If date is selected, use the selected date as the end of the year
    )


VAR SalesInRange = 
    CALCULATE(
        [ActualSales],  -- Calculate the sales measure
        'CalendarFY'[Date] &amp;gt;= StartfYear &amp;amp;&amp;amp; 'CalendarFY'[Date] &amp;lt;= EndfYear   &amp;amp;&amp;amp; 'CalendarFY'[year] &amp;gt;=  YEAR(StartfYear) &amp;amp;&amp;amp; 'CalendarFY'[year] &amp;lt;=  YEAR(EndfYear)
    )
RETURN
    IF(ISBLANK(SalesInRange), 0, SalesInRange)  -- Return 0 if no sales data is found for the given period&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;The final result is as follows. The line chart will be a zero line for the month following the selected date.&lt;/P&gt;
&lt;P&gt;&lt;img /&gt;&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;Please see the attached pbix for reference.&lt;BR /&gt;&lt;BR /&gt;Best Regards,&lt;BR /&gt;Dengliang Li&lt;BR /&gt;&lt;BR /&gt;If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.&lt;/P&gt;</description>
      <pubDate>Mon, 06 Jan 2025 05:20:17 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Previous-months-data-generated-for-line-chart/m-p/4351336#M172800</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2025-01-06T05:20:17Z</dc:date>
    </item>
    <item>
      <title>Re: Previous  months data generated for line chart</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Previous-months-data-generated-for-line-chart/m-p/4351666#M172810</link>
      <description>Thank you for help</description>
      <pubDate>Mon, 06 Jan 2025 09:35:45 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Previous-months-data-generated-for-line-chart/m-p/4351666#M172810</guid>
      <dc:creator>Puja_Kumari25</dc:creator>
      <dc:date>2025-01-06T09:35:45Z</dc:date>
    </item>
  </channel>
</rss>

