<?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: Measure to return value for same location and between start and end date in DAX Commands and Tips</title>
    <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Measure-to-return-value-for-same-location-and-between-start-and/m-p/3412677#M129020</link>
    <description>&lt;P&gt;First, you'll want to create a relationship between your baseline data and your lookup table based on the 'Location' column. This will allow you to reference the lookup table's columns in your DAX measure.&lt;/P&gt;
&lt;P&gt;Next, for the measure, you'll want to use the RELATED function to pull the related values from the lookup table based on the selected location in the baseline data.&lt;/P&gt;
&lt;P&gt;The logic you want to implement is to check if the current year in the baseline data is within the range of the 'Start Year' and 'Start Year' + 'No. of Years'. If it is, then you'll return the 'Demand per year' value, otherwise, you'll return 0.&lt;/P&gt;
&lt;P&gt;Here's a DAX measure that should do the trick:&lt;/P&gt;
&lt;P&gt;Water Demand Measure = &lt;BR /&gt;VAR CurrentYear = SELECTEDVALUE('Baseline Data'[Year])&lt;BR /&gt;VAR StartYear = RELATED('Lookup Table'[Start Year])&lt;BR /&gt;VAR Duration = RELATED('Lookup Table'[No. of Years])&lt;BR /&gt;VAR Demand = RELATED('Lookup Table'[Demand per year])&lt;/P&gt;
&lt;P&gt;RETURN&lt;BR /&gt;IF(&lt;BR /&gt;AND(CurrentYear &amp;gt;= StartYear, CurrentYear &amp;lt;= StartYear + Duration),&lt;BR /&gt;Demand,&lt;BR /&gt;0&lt;BR /&gt;)&lt;BR /&gt;In this measure, we're first defining some variables to make the formula easier to read. We're grabbing the current year from the baseline data, and then using the RELATED function to get the corresponding 'Start Year', 'No. of Years', and 'Demand per year' values from the lookup table.&lt;/P&gt;
&lt;P&gt;The IF and AND functions are then used to check if the current year is within the range defined by the 'Start Year' and 'Start Year' + 'No. of Years'. If it is, we return the 'Demand per year' value, otherwise, we return 0.&lt;/P&gt;
&lt;P&gt;Once you've created this measure, you can use it in your dashboard to display the water demand for any selected location and year.&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Sun, 03 Sep 2023 16:45:39 GMT</pubDate>
    <dc:creator>technolog</dc:creator>
    <dc:date>2023-09-03T16:45:39Z</dc:date>
    <item>
      <title>Measure to return value for same location and between start and end date</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Measure-to-return-value-for-same-location-and-between-start-and/m-p/983757#M12043</link>
      <description>&lt;P&gt;Hi there,&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Appreciate any help I can get with the problem I am trying to solve below.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am building a Power BI model that estimates the demand for water for a number of different sources. Each 'source' of demand for water has it's own excel sheet containing 'factors' relevant to that source of demand. The 'factors' are pulled into the model and generally multiplied against a baseline data set.&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;One of the demand sources I am struggling with is for the closure of the plant. The 'factors' that I am given to work with for this 'source' of demand is in the format below:&lt;/P&gt;&lt;TABLE border="1"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;&lt;STRONG&gt;Location&lt;/STRONG&gt;&lt;/TD&gt;&lt;TD&gt;&lt;STRONG&gt;Start Year&lt;/STRONG&gt;&lt;/TD&gt;&lt;TD&gt;&lt;STRONG&gt;No. of Years&lt;/STRONG&gt;&lt;/TD&gt;&lt;TD&gt;&lt;STRONG&gt;Demand per year&lt;/STRONG&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;A&lt;/TD&gt;&lt;TD&gt;2020&lt;/TD&gt;&lt;TD&gt;10&lt;/TD&gt;&lt;TD&gt;2&lt;/TD&gt;&lt;/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;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am trying to write a measure so that in the dashboard, whenever I select a particular location (A,B,...) and year (2020,2021,...) the measure will:&lt;/P&gt;&lt;OL&gt;&lt;LI&gt;Look up the 'location' in the lookup table,&lt;/LI&gt;&lt;LI&gt;Work out if the current year (in the baseline data) is between the 'start year' and the 'start year' + 'no. of years' in the lookup table&lt;/LI&gt;&lt;LI&gt;Return the number in the 'demand per year' column in the lookup table&lt;/LI&gt;&lt;/OL&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Let me know if you have any thoughts! I can't seem to find anything relevant online and not sure how to start...&lt;/P&gt;</description>
      <pubDate>Fri, 20 Mar 2020 09:46:18 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Measure-to-return-value-for-same-location-and-between-start-and/m-p/983757#M12043</guid>
      <dc:creator>ElHeatho</dc:creator>
      <dc:date>2020-03-20T09:46:18Z</dc:date>
    </item>
    <item>
      <title>Re: Measure to return value for same location and between start and end date</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Measure-to-return-value-for-same-location-and-between-start-and/m-p/3412677#M129020</link>
      <description>&lt;P&gt;First, you'll want to create a relationship between your baseline data and your lookup table based on the 'Location' column. This will allow you to reference the lookup table's columns in your DAX measure.&lt;/P&gt;
&lt;P&gt;Next, for the measure, you'll want to use the RELATED function to pull the related values from the lookup table based on the selected location in the baseline data.&lt;/P&gt;
&lt;P&gt;The logic you want to implement is to check if the current year in the baseline data is within the range of the 'Start Year' and 'Start Year' + 'No. of Years'. If it is, then you'll return the 'Demand per year' value, otherwise, you'll return 0.&lt;/P&gt;
&lt;P&gt;Here's a DAX measure that should do the trick:&lt;/P&gt;
&lt;P&gt;Water Demand Measure = &lt;BR /&gt;VAR CurrentYear = SELECTEDVALUE('Baseline Data'[Year])&lt;BR /&gt;VAR StartYear = RELATED('Lookup Table'[Start Year])&lt;BR /&gt;VAR Duration = RELATED('Lookup Table'[No. of Years])&lt;BR /&gt;VAR Demand = RELATED('Lookup Table'[Demand per year])&lt;/P&gt;
&lt;P&gt;RETURN&lt;BR /&gt;IF(&lt;BR /&gt;AND(CurrentYear &amp;gt;= StartYear, CurrentYear &amp;lt;= StartYear + Duration),&lt;BR /&gt;Demand,&lt;BR /&gt;0&lt;BR /&gt;)&lt;BR /&gt;In this measure, we're first defining some variables to make the formula easier to read. We're grabbing the current year from the baseline data, and then using the RELATED function to get the corresponding 'Start Year', 'No. of Years', and 'Demand per year' values from the lookup table.&lt;/P&gt;
&lt;P&gt;The IF and AND functions are then used to check if the current year is within the range defined by the 'Start Year' and 'Start Year' + 'No. of Years'. If it is, we return the 'Demand per year' value, otherwise, we return 0.&lt;/P&gt;
&lt;P&gt;Once you've created this measure, you can use it in your dashboard to display the water demand for any selected location and year.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 03 Sep 2023 16:45:39 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Measure-to-return-value-for-same-location-and-between-start-and/m-p/3412677#M129020</guid>
      <dc:creator>technolog</dc:creator>
      <dc:date>2023-09-03T16:45:39Z</dc:date>
    </item>
  </channel>
</rss>

