<?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 Measure to return a field based on two measures comparison in DAX Commands and Tips</title>
    <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Measure-to-return-a-field-based-on-two-measures-comparison/m-p/3222160#M117805</link>
    <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have a measure named 'Total Cost' that is based on (SUM('Table1'[Qty]) *&amp;nbsp;SUM('Table2'[Cost]).&lt;BR /&gt;This 'Total Cost' is break by Item, Origin and Destination in a table resulting in:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Item | Origin | Destination | Total Cost&lt;BR /&gt;123 | BRA | BEL | 100&lt;BR /&gt;123 | ARG | BEL | 120&lt;/P&gt;&lt;P&gt;312 | BRA | COL | 300&lt;BR /&gt;(...)&lt;BR /&gt;&lt;BR /&gt;I've created a 'Min Total Cost' measure to point out the best source cost:&lt;/P&gt;&lt;P&gt;CALCULATE(&lt;BR /&gt;MINX('Table2',[Total Cost]),&lt;BR /&gt;ALLSELECTED('Table2[Origin],'Table2'[Item-Origin])&lt;BR /&gt;)&lt;BR /&gt;&lt;BR /&gt;This measure is working fine, so added to above:&lt;BR /&gt;Item | Origin | Destination | Total Cost | Min Cost&lt;BR /&gt;123 | BRA | BEL | 100 | 100&lt;BR /&gt;123 | ARG | BEL | 120 | 100&lt;BR /&gt;&lt;BR /&gt;Now I want to point out what is the best source in each of the lines.&lt;BR /&gt;Item | Origin | Destination | Total Cost | Min Cost | &lt;FONT color="#FF0000"&gt;Best Origin&lt;/FONT&gt;&lt;BR /&gt;123 | BRA | BEL | 100 | 100 | &lt;FONT color="#FF0000"&gt;BRA&lt;/FONT&gt;&lt;BR /&gt;123 | ARG | BEL | 120 | 100 | &lt;FONT color="#FF0000"&gt;BRA&lt;BR /&gt;&lt;BR /&gt;&lt;/FONT&gt;How can I create the measure to point the 'Best Origin'?&lt;/P&gt;</description>
    <pubDate>Fri, 05 May 2023 13:05:05 GMT</pubDate>
    <dc:creator>AndreGiovannini</dc:creator>
    <dc:date>2023-05-05T13:05:05Z</dc:date>
    <item>
      <title>Measure to return a field based on two measures comparison</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Measure-to-return-a-field-based-on-two-measures-comparison/m-p/3222160#M117805</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have a measure named 'Total Cost' that is based on (SUM('Table1'[Qty]) *&amp;nbsp;SUM('Table2'[Cost]).&lt;BR /&gt;This 'Total Cost' is break by Item, Origin and Destination in a table resulting in:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Item | Origin | Destination | Total Cost&lt;BR /&gt;123 | BRA | BEL | 100&lt;BR /&gt;123 | ARG | BEL | 120&lt;/P&gt;&lt;P&gt;312 | BRA | COL | 300&lt;BR /&gt;(...)&lt;BR /&gt;&lt;BR /&gt;I've created a 'Min Total Cost' measure to point out the best source cost:&lt;/P&gt;&lt;P&gt;CALCULATE(&lt;BR /&gt;MINX('Table2',[Total Cost]),&lt;BR /&gt;ALLSELECTED('Table2[Origin],'Table2'[Item-Origin])&lt;BR /&gt;)&lt;BR /&gt;&lt;BR /&gt;This measure is working fine, so added to above:&lt;BR /&gt;Item | Origin | Destination | Total Cost | Min Cost&lt;BR /&gt;123 | BRA | BEL | 100 | 100&lt;BR /&gt;123 | ARG | BEL | 120 | 100&lt;BR /&gt;&lt;BR /&gt;Now I want to point out what is the best source in each of the lines.&lt;BR /&gt;Item | Origin | Destination | Total Cost | Min Cost | &lt;FONT color="#FF0000"&gt;Best Origin&lt;/FONT&gt;&lt;BR /&gt;123 | BRA | BEL | 100 | 100 | &lt;FONT color="#FF0000"&gt;BRA&lt;/FONT&gt;&lt;BR /&gt;123 | ARG | BEL | 120 | 100 | &lt;FONT color="#FF0000"&gt;BRA&lt;BR /&gt;&lt;BR /&gt;&lt;/FONT&gt;How can I create the measure to point the 'Best Origin'?&lt;/P&gt;</description>
      <pubDate>Fri, 05 May 2023 13:05:05 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Measure-to-return-a-field-based-on-two-measures-comparison/m-p/3222160#M117805</guid>
      <dc:creator>AndreGiovannini</dc:creator>
      <dc:date>2023-05-05T13:05:05Z</dc:date>
    </item>
    <item>
      <title>Re: Measure to return a field based on two measures comparison</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Measure-to-return-a-field-based-on-two-measures-comparison/m-p/3222276#M117820</link>
      <description>&lt;P&gt;hello please follow&lt;BR /&gt;&lt;BR /&gt;first you can shorten your measure for minx with&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;Lowest price = 
MINX(
    ALLSELECTED('Table'[Origin]),
    [Sum cost]
)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;second you need to use topn&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;origin best = 
TOPN(
    1,ALLSELECTED('Table'[Origin]),[Sum cost],ASC)&lt;/LI-CODE&gt;&lt;P&gt;&lt;img /&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 05 May 2023 14:00:35 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Measure-to-return-a-field-based-on-two-measures-comparison/m-p/3222276#M117820</guid>
      <dc:creator>eliasayyy</dc:creator>
      <dc:date>2023-05-05T14:00:35Z</dc:date>
    </item>
    <item>
      <title>Re: Measure to return a field based on two measures comparison</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Measure-to-return-a-field-based-on-two-measures-comparison/m-p/3222447#M117834</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="javascript:void(0)" data-lia-user-mentions="" data-lia-user-uid="434309" data-lia-user-login="eliasayyy" class="lia-mention lia-mention-user"&gt;eliasayyy&lt;/a&gt;&amp;nbsp;,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The image you sent is exactly what I need, but I could not replicate it in my model.&lt;/P&gt;&lt;P&gt;There is no error flag on measure, but once add it to a visual the following msg appears:&lt;/P&gt;&lt;P&gt;"MdxScript(Model) (75,1) Calculation error in measure 'SUP Measures'[Best Source]: A table of multiple values was supplied where a singular value was expected."&lt;BR /&gt;&lt;BR /&gt;I believe that this is related to fields I'm aggregating in ALLSELECTED. Tried some other selections but couldnt solve it.&lt;BR /&gt;&lt;BR /&gt;Any thougts of what I'm missing?&lt;/P&gt;</description>
      <pubDate>Fri, 05 May 2023 15:12:05 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Measure-to-return-a-field-based-on-two-measures-comparison/m-p/3222447#M117834</guid>
      <dc:creator>AndreGiovannini</dc:creator>
      <dc:date>2023-05-05T15:12:05Z</dc:date>
    </item>
    <item>
      <title>Re: Measure to return a field based on two measures comparison</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Measure-to-return-a-field-based-on-two-measures-comparison/m-p/3222489#M117835</link>
      <description>&lt;P&gt;Can you send me the measure you used&lt;/P&gt;</description>
      <pubDate>Fri, 05 May 2023 15:33:12 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Measure-to-return-a-field-based-on-two-measures-comparison/m-p/3222489#M117835</guid>
      <dc:creator>eliasayyy</dc:creator>
      <dc:date>2023-05-05T15:33:12Z</dc:date>
    </item>
    <item>
      <title>Re: Measure to return a field based on two measures comparison</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Measure-to-return-a-field-based-on-two-measures-comparison/m-p/3222572#M117854</link>
      <description>&lt;P&gt;Sure, here is it:&lt;BR /&gt;&lt;BR /&gt;Best Source =&lt;BR /&gt;TOPN(1,&lt;BR /&gt;ALLSELECTED('DIM Avail Org'[Avail Org Code])&lt;BR /&gt;,[Total Landed]&lt;BR /&gt;,ASC)&lt;BR /&gt;&lt;BR /&gt;I've been playing around with fields on ALLSELECTED, but couldnt solve it yet.&lt;BR /&gt;&lt;BR /&gt;EDIT:&lt;BR /&gt;There is a Joiner table affecting this measure. Added the 'ALLEXCEPT' and measure do no break anymore. However I could not identify which exceptions should I use yet.&lt;BR /&gt;&lt;BR /&gt;Best Source =&lt;BR /&gt;CALCULATE(&lt;BR /&gt;TOPN(1,&lt;BR /&gt;ALLSELECTED(JNR[Avail Org])&lt;BR /&gt;,[Total Landed]&lt;BR /&gt;,ASC)&lt;BR /&gt;,ALLEXCEPT(JNR,JNR[Avail Org]&lt;BR /&gt;))&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 05 May 2023 18:21:16 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Measure-to-return-a-field-based-on-two-measures-comparison/m-p/3222572#M117854</guid>
      <dc:creator>AndreGiovannini</dc:creator>
      <dc:date>2023-05-05T18:21:16Z</dc:date>
    </item>
    <item>
      <title>Re: Measure to return a field based on two measures comparison</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Measure-to-return-a-field-based-on-two-measures-comparison/m-p/3222695#M117870</link>
      <description>&lt;P&gt;Is there a relationship between table 1 and table 2?&lt;/P&gt;</description>
      <pubDate>Fri, 05 May 2023 18:10:24 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Measure-to-return-a-field-based-on-two-measures-comparison/m-p/3222695#M117870</guid>
      <dc:creator>eliasayyy</dc:creator>
      <dc:date>2023-05-05T18:10:24Z</dc:date>
    </item>
    <item>
      <title>Re: Measure to return a field based on two measures comparison</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Measure-to-return-a-field-based-on-two-measures-comparison/m-p/3225610#M118126</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="javascript:void(0)" data-lia-user-mentions="" data-lia-user-uid="434309" data-lia-user-login="eliasayyy" class="lia-mention lia-mention-user"&gt;eliasayyy&lt;/a&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Flagging your solution as accepted. Was able to replicated it in a different data model.&lt;/P&gt;&lt;P&gt;Thank you.&lt;/P&gt;</description>
      <pubDate>Mon, 08 May 2023 20:17:19 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Measure-to-return-a-field-based-on-two-measures-comparison/m-p/3225610#M118126</guid>
      <dc:creator>AndreGiovannini</dc:creator>
      <dc:date>2023-05-08T20:17:19Z</dc:date>
    </item>
  </channel>
</rss>

