<?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: Calculate with Filtering on AccountID (hardcoded) is working but not working on AccountID (dynamic) in DAX Commands and Tips</title>
    <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Calculate-with-Filtering-on-AccountID-hardcoded-is-working-but/m-p/3637929#M140793</link>
    <description>&lt;P&gt;What's the actual issue with the "Hardcoded Accounts"&amp;nbsp; measure?&amp;nbsp; Seems to be a reasonable approach.&lt;/P&gt;</description>
    <pubDate>Mon, 15 Jan 2024 01:14:42 GMT</pubDate>
    <dc:creator>lbendlin</dc:creator>
    <dc:date>2024-01-15T01:14:42Z</dc:date>
    <item>
      <title>Calculate with Filtering on AccountID (hardcoded) is working but not working on AccountID (dynamic)</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Calculate-with-Filtering-on-AccountID-hardcoded-is-working-but/m-p/3636647#M140700</link>
      <description>&lt;P&gt;Hi everyone. I have a created a DAX measures in which &lt;STRONG&gt;there is a filtering on Account ID column of COADetails table&lt;/STRONG&gt;.&lt;STRONG&gt;&amp;nbsp;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;Now the issue is that, in the measure, when I write the Account ID numbers as hardcoded, the measure works, but when I write those dynamically, it doesn't work. To avoid confusion, I have created the same DAX measure twice, one being hardcoded and the other being dynamic -&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;img /&gt;&lt;/P&gt;&lt;P&gt;I am providing the necessary files i.e. the datasource (excel file) and the Power BI report which you will get in the below link -&amp;nbsp;&lt;BR /&gt;&lt;A href="https://drive.google.com/drive/folders/1xDiFgNOm_OpwcqfcgNhInF1homob_suP?usp=sharing" target="_blank"&gt;https://drive.google.com/drive/folders/1xDiFgNOm_OpwcqfcgNhInF1homob_suP?usp=sharing&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;Can anybody please tell me what am I doing wrong ?&lt;/P&gt;</description>
      <pubDate>Fri, 12 Jan 2024 19:52:37 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Calculate-with-Filtering-on-AccountID-hardcoded-is-working-but/m-p/3636647#M140700</guid>
      <dc:creator>Gazi_Sohan</dc:creator>
      <dc:date>2024-01-12T19:52:37Z</dc:date>
    </item>
    <item>
      <title>Re: Calculate with Filtering on AccountID (hardcoded) is working but not working on AccountID (dynamic)</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Calculate-with-Filtering-on-AccountID-hardcoded-is-working-but/m-p/3637929#M140793</link>
      <description>&lt;P&gt;What's the actual issue with the "Hardcoded Accounts"&amp;nbsp; measure?&amp;nbsp; Seems to be a reasonable approach.&lt;/P&gt;</description>
      <pubDate>Mon, 15 Jan 2024 01:14:42 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Calculate-with-Filtering-on-AccountID-hardcoded-is-working-but/m-p/3637929#M140793</guid>
      <dc:creator>lbendlin</dc:creator>
      <dc:date>2024-01-15T01:14:42Z</dc:date>
    </item>
    <item>
      <title>Re: Calculate with Filtering on AccountID (hardcoded) is working but not working on AccountID (dynamic)</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Calculate-with-Filtering-on-AccountID-hardcoded-is-working-but/m-p/3637934#M140794</link>
      <description>&lt;P&gt;Hi,&amp;nbsp;&lt;a href="javascript:void(0)" data-lia-user-mentions="" data-lia-user-uid="608733" data-lia-user-login="Gazi_Sohan" class="lia-mention lia-mention-user"&gt;Gazi_Sohan&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;here is my solution:&lt;/P&gt;
&lt;P&gt;The condition you set in the measure's calculate function is incorrect, we also need to restrict the Category. To solve this wrong, use the following DAX expression：&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;Dynamic Accounts = 
var selectedrecord = SELECTEDVALUE('COA Summary'[Account ID])
RETURN
SWITCH(
    selectedrecord,
    106,
    CALCULATE(
        SUM(Transactions[Amount]),
        ALL('COA Details'),
        'COA Details'[Category]="Revenues"&amp;amp;&amp;amp;
        'COA Details'[Account ID] &amp;gt;= 'COA Details'[Operator Between Start]
        &amp;amp;&amp;amp; 'COA Details'[Account ID] &amp;lt;= 'COA Details'[Operator Between End]
    ),
    206,
    CALCULATE(
        SUM(Transactions[Amount]),
        ALL('COA Details'),
        'COA Details'[Category]="Expenses"&amp;amp;&amp;amp;
        'COA Details'[Account ID] &amp;gt;= 'COA Details'[Operator Between Start]
        &amp;amp;&amp;amp; 'COA Details'[Account ID] &amp;lt;= 'COA Details'[Operator Between End]
    ),
    CALCULATE(
        SUM(Transactions[Amount]),
        'COA Details'[Account ID] &amp;gt;= 'COA Details'[Operator Between Start]
        &amp;amp;&amp;amp; 'COA Details'[Account ID] &amp;lt;= 'COA Details'[Operator Between End]
    )
)
&lt;/LI-CODE&gt;
&lt;P&gt;A screenshot of the formula is shown below:&lt;/P&gt;
&lt;P&gt;&lt;img /&gt;&lt;/P&gt;
&lt;P&gt;The results are as follows:&lt;/P&gt;
&lt;P&gt;&lt;img /&gt;&lt;/P&gt;
&lt;P&gt;This way we can get the correct Total Expenses and Total Revenues by dynamic measure.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;A href="https://nam06.safelinks.protection.outlook.com/?url=https%3A%2F%2Fcommunity.powerbi.com%2Ft5%2FCommunity-Blog%2FHow-to-Get-Your-Question-Answered-Quickly%2Fba-p%2F38490&amp;amp;data=05%7C02%7Cv-jianpengli%40microsoft.com%7C919d5b1a4f454b28ed6b08dc15666373%7C72f988bf86f141af91ab2d7cd011db47%7C1%7C0%7C638408776714815902%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&amp;amp;sdata=jUJ9H1jYI5HQQG%2BjG7kmbs2FHhcVd31ttcCX9Uaq0bs%3D&amp;amp;reserved=0" target="_blank"&gt;How to Get Your Question Answered Quickly&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;If it does not help, please provide more details with your desired output and pbix file without privacy information (or some sample data) .&lt;/P&gt;
&lt;P&gt;Best Regards&lt;/P&gt;
&lt;P&gt;Jianpeng Li&lt;/P&gt;
&lt;P&gt;If this post&amp;nbsp;&lt;STRONG&gt;&lt;EM&gt;helps&lt;/EM&gt;&lt;/STRONG&gt;, then please consider&amp;nbsp;&lt;STRONG&gt;&lt;EM&gt;Accept it as the solution&lt;/EM&gt;&lt;/STRONG&gt;&amp;nbsp;to help the other members find it more quickly.&lt;/P&gt;</description>
      <pubDate>Mon, 15 Jan 2024 01:16:17 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Calculate-with-Filtering-on-AccountID-hardcoded-is-working-but/m-p/3637934#M140794</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2024-01-15T01:16:17Z</dc:date>
    </item>
    <item>
      <title>Re: Calculate with Filtering on AccountID (hardcoded) is working but not working on AccountID (dynamic)</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Calculate-with-Filtering-on-AccountID-hardcoded-is-working-but/m-p/3649339#M141347</link>
      <description>&lt;P&gt;Anonymous&lt;/a&gt;&amp;nbsp;&lt;BR /&gt;Thanks for your reply.&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;In reality, we can't use the &lt;STRONG&gt;Category&lt;/STRONG&gt; column because in the real report/file, we have to add Net Income which is not as easy as revenue/expense that you have shown in the filtering portion. Net Income is a combination of 7-8 categories including some blank categories in our main file.&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;&lt;SPAN class=""&gt;We can't do this in our main file as because we only do have lots of Account Sub Categories when taken into consideration for calculating Net Income&amp;nbsp;(Account Sub Category in the picture is basically the same as Category in the sample file that I provided) -&amp;nbsp;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;img /&gt;&lt;/P&gt;&lt;P&gt;Just like Revenue and Expenses (you included&amp;nbsp;&lt;STRONG&gt;Category = "Revenue" and Category = "Expenses"&lt;/STRONG&gt; within the calculate function), we can't do the same for Net Income (&lt;STRONG&gt;Category = "Net Income"&lt;/STRONG&gt;) as because it's not straightforward like Revenue and Expenses. Instead, Net Income is a combination of lots of categories as shown in the picture, it also includes blanks.&lt;BR /&gt;&lt;BR /&gt;Also, if we use&amp;nbsp;&lt;STRONG&gt;Category&lt;/STRONG&gt; as a filter, then we actually don't need this part at all -&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;'COA Details'[Account ID] &amp;gt;= 'COA Details'[Operator Between Start]
        &amp;amp;&amp;amp; 'COA Details'[Account ID] &amp;lt;= 'COA Details'[Operator Between End]&lt;/PRE&gt;&lt;P&gt;&lt;SPAN&gt;&lt;SPAN class=""&gt;because Category filter will automatically filter the accounts underneath.&lt;BR /&gt;&lt;BR /&gt;Summary is -&amp;nbsp;&lt;STRONG&gt;We can't use Category as a filter, instead we must have to anyhow use the AccountID, but it should not be hardcoded rather dynamic&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Sat, 20 Jan 2024 06:12:32 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Calculate-with-Filtering-on-AccountID-hardcoded-is-working-but/m-p/3649339#M141347</guid>
      <dc:creator>Gazi_Sohan</dc:creator>
      <dc:date>2024-01-20T06:12:32Z</dc:date>
    </item>
    <item>
      <title>Re: Calculate with Filtering on AccountID (hardcoded) is working but not working on AccountID (dynamic)</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Calculate-with-Filtering-on-AccountID-hardcoded-is-working-but/m-p/3652961#M141517</link>
      <description>&lt;P&gt;Hey&amp;nbsp;&lt;a href="javascript:void(0)" data-lia-user-mentions="" data-lia-user-uid="100342" data-lia-user-login="lbendlin" class="lia-mention lia-mention-user"&gt;lbendlin&lt;/a&gt;&amp;nbsp;&lt;BR /&gt;Sorry for the late reply to your question. Hardcoded means using raw numbers, for example, under the calculate function, we are using&amp;nbsp;&lt;STRONG&gt;AccountID &amp;gt;= 400000 &amp;amp;&amp;amp; AccountID &amp;lt;= 957090.&amp;nbsp;&lt;/STRONG&gt;Here&amp;nbsp;&lt;STRONG&gt;400000&lt;/STRONG&gt; and&amp;nbsp;&lt;STRONG&gt;957090&lt;/STRONG&gt; - these 2 are hardcoded numbers.&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;Now, if you download the sample files, you will see that this numbers are present in the &lt;STRONG&gt;COA Details&lt;/STRONG&gt; table under 2 columns -&amp;nbsp;&lt;STRONG&gt;Operator Between Start&lt;/STRONG&gt; and&amp;nbsp;&lt;STRONG&gt;Operator Between End.&lt;/STRONG&gt;&lt;BR /&gt;&lt;BR /&gt;So, the summary is - we don't wan't to use&amp;nbsp;&lt;STRONG&gt;AccountID &amp;gt;= 400000 &amp;amp;&amp;amp; AccountID &amp;lt;= 957090&lt;/STRONG&gt; inside our measure, Instead we want to use&amp;nbsp;&lt;STRONG&gt;AccountID &amp;gt;= Operator Between Start &amp;amp;&amp;amp;&amp;nbsp;AccountID &amp;lt;=&amp;nbsp;Operator Between End.&lt;BR /&gt;&lt;BR /&gt;&lt;/STRONG&gt;Btw, we can't use the&amp;nbsp;&lt;STRONG&gt;Category&amp;nbsp;&lt;/STRONG&gt;column and I explained the reason why (see my other replies).&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 23 Jan 2024 03:38:31 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Calculate-with-Filtering-on-AccountID-hardcoded-is-working-but/m-p/3652961#M141517</guid>
      <dc:creator>Gazi_Sohan</dc:creator>
      <dc:date>2024-01-23T03:38:31Z</dc:date>
    </item>
    <item>
      <title>Re: Calculate with Filtering on AccountID (hardcoded) is working but not working on AccountID (dynamic)</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Calculate-with-Filtering-on-AccountID-hardcoded-is-working-but/m-p/3663316#M141963</link>
      <description>&lt;P&gt;Hey&amp;nbsp;Anonymous&lt;/a&gt;&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;I have tried my own way by using a pretty simple approach i.e. using&amp;nbsp;&lt;STRONG&gt;selectedvalue&lt;/STRONG&gt; function and it's working perfect in the measure and made it dynamic -&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;img /&gt;&lt;BR /&gt;&lt;BR /&gt;I have applied the same concept in the sample POC file that I provided for you (attached) -&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;&lt;img /&gt;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;and it's also working fine in the sample file -&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;img /&gt;&lt;/P&gt;&lt;P&gt;But anyway, thanks for your help. I really appreciate it. You are a very talneted guy I must say.&lt;BR /&gt;Hats off&amp;nbsp;&lt;span class="lia-unicode-emoji" title=":collision:"&gt;💥&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;.pbix file with my dynamic measure -&amp;nbsp;&lt;BR /&gt;&lt;A href="https://drive.google.com/file/d/1jRhL9q_ytVP4OxSyjntFliLqdm_IXynP/view?usp=sharing" target="_blank" rel="noopener"&gt;https://drive.google.com/file/d/1jRhL9q_ytVP4OxSyjntFliLqdm_IXynP/view?usp=sharing&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 26 Jan 2024 19:18:14 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Calculate-with-Filtering-on-AccountID-hardcoded-is-working-but/m-p/3663316#M141963</guid>
      <dc:creator>Gazi_Sohan</dc:creator>
      <dc:date>2024-01-26T19:18:14Z</dc:date>
    </item>
  </channel>
</rss>

