<?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 How to provide the right row context using an existing measure in DAX Commands and Tips</title>
    <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/How-to-provide-the-right-row-context-using-an-existing-measure/m-p/2255932#M54442</link>
    <description>&lt;P&gt;Hello,&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;I would like to know if there is a better way to solve this situation.&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;I have a measure that, given a fact table, calculates scores.&amp;nbsp;&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;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;ScoreRegion = CALCULATE(ROUND(DIVIDE(SUM(ScoresRegion[Orig_Num]), SUM(ScoresRegion[Orig_Denom])),2)*100)&lt;/LI-CODE&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;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;I need to create another measure that, given a score, calculates a five point scale value depending on the target of that score.&lt;/P&gt;&lt;P&gt;The target is available as a column in the same ScoresRegion table.&lt;/P&gt;&lt;P&gt;&lt;img /&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;I wanted to reuse the Score Region measure.&lt;/P&gt;&lt;P&gt;An iterator function&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;LI-CODE lang="markup"&gt;SUMX(ScoresRegion, ...​&lt;/LI-CODE&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;BR /&gt;would create a row context, but I get incorrect Score Region values, since it appears that the Score would be evaluated in every row, and wont aggregate cases where there is more that one score entry.&lt;/P&gt;&lt;P&gt;The solution I have right now uses SUMMARIZE to create the correct 'table' and row context where to iterate, and then ADDCOLUMNS to create the desired output. I replicated this pattern on other various measures.&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;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;5p RAW Score Region =


VAR AggFact = ADDCOLUMNS(

SUMMARIZE(
ScoresRegion
,ScoresRegion[MetricId]
,ScoresRegion[Target]
,Metric[TargetLogic]
,Metric[NoTarget]
,Metric[Inverse]
,Metric[SegmentId]
,Metric[Unit]

)
, "5pScaleScoreRAW", SWITCH(TRUE()
,[Inverse] = 0 &amp;amp;&amp;amp; Metric[TargetLogic] &amp;lt;&amp;gt; "n/a" , ROUND(DIVIDE([Score Region],'ScoresRegion'[Target]),2)*5
,[Inverse] = 1 &amp;amp;&amp;amp; Metric[TargetLogic] &amp;lt;&amp;gt; "n/a" , ROUND(DIVIDE(
(100-[Score Region])
,(100-[Target])),2)*5
,BLANK())
)


RETURN

SUMX(AggFact, [5pScaleScoreRAW])​

 &lt;/LI-CODE&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;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;I noticed that the model takes too much memory (sometimes up to 9 GB) for its size (30k score rows or so).&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;I was wondering if this practice is expensive in terms of memory, and if there is an other more efficient, obviouss, natural way to achieve it.&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;Thanks&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;</description>
    <pubDate>Sun, 26 Dec 2021 18:25:04 GMT</pubDate>
    <dc:creator>Anonymous</dc:creator>
    <dc:date>2021-12-26T18:25:04Z</dc:date>
    <item>
      <title>How to provide the right row context using an existing measure</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/How-to-provide-the-right-row-context-using-an-existing-measure/m-p/2255932#M54442</link>
      <description>&lt;P&gt;Hello,&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;I would like to know if there is a better way to solve this situation.&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;I have a measure that, given a fact table, calculates scores.&amp;nbsp;&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;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;ScoreRegion = CALCULATE(ROUND(DIVIDE(SUM(ScoresRegion[Orig_Num]), SUM(ScoresRegion[Orig_Denom])),2)*100)&lt;/LI-CODE&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;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;I need to create another measure that, given a score, calculates a five point scale value depending on the target of that score.&lt;/P&gt;&lt;P&gt;The target is available as a column in the same ScoresRegion table.&lt;/P&gt;&lt;P&gt;&lt;img /&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;I wanted to reuse the Score Region measure.&lt;/P&gt;&lt;P&gt;An iterator function&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;LI-CODE lang="markup"&gt;SUMX(ScoresRegion, ...​&lt;/LI-CODE&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;BR /&gt;would create a row context, but I get incorrect Score Region values, since it appears that the Score would be evaluated in every row, and wont aggregate cases where there is more that one score entry.&lt;/P&gt;&lt;P&gt;The solution I have right now uses SUMMARIZE to create the correct 'table' and row context where to iterate, and then ADDCOLUMNS to create the desired output. I replicated this pattern on other various measures.&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;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;5p RAW Score Region =


VAR AggFact = ADDCOLUMNS(

SUMMARIZE(
ScoresRegion
,ScoresRegion[MetricId]
,ScoresRegion[Target]
,Metric[TargetLogic]
,Metric[NoTarget]
,Metric[Inverse]
,Metric[SegmentId]
,Metric[Unit]

)
, "5pScaleScoreRAW", SWITCH(TRUE()
,[Inverse] = 0 &amp;amp;&amp;amp; Metric[TargetLogic] &amp;lt;&amp;gt; "n/a" , ROUND(DIVIDE([Score Region],'ScoresRegion'[Target]),2)*5
,[Inverse] = 1 &amp;amp;&amp;amp; Metric[TargetLogic] &amp;lt;&amp;gt; "n/a" , ROUND(DIVIDE(
(100-[Score Region])
,(100-[Target])),2)*5
,BLANK())
)


RETURN

SUMX(AggFact, [5pScaleScoreRAW])​

 &lt;/LI-CODE&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;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;I noticed that the model takes too much memory (sometimes up to 9 GB) for its size (30k score rows or so).&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;I was wondering if this practice is expensive in terms of memory, and if there is an other more efficient, obviouss, natural way to achieve it.&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;Thanks&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Sun, 26 Dec 2021 18:25:04 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/How-to-provide-the-right-row-context-using-an-existing-measure/m-p/2255932#M54442</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2021-12-26T18:25:04Z</dc:date>
    </item>
    <item>
      <title>Re: How to provide the right row context using an existing measure</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/How-to-provide-the-right-row-context-using-an-existing-measure/m-p/2256085#M54452</link>
      <description>&lt;P&gt;I think refactoring it along these lines should be more efficient.&lt;/P&gt;
&lt;LI-CODE lang="php"&gt;CALCULATE (
    SUMX (
        SUMMARIZE ( ScoresRegion, ScoresRegion[MetricId], ScoresRegion[Target] ),
        ROUND ( DIVIDE ( [Score Region], 'ScoresRegion'[Target] ), 2 ) * 5
    ),
    KEEPFILTERS ( Metric[Inverse] = 0 ),
    KEEPFILTERS ( Metric[TargetLogic] &amp;lt;&amp;gt; "n/a" )
) +
CALCULATE (
    SUMX (
        SUMMARIZE ( ScoresRegion, ScoresRegion[MetricId], ScoresRegion[Target] ),
        ROUND ( DIVIDE ( 100 - [Score Region], 100 - 'ScoresRegion'[Target] ), 2 ) * 5
    ),
    KEEPFILTERS ( Metric[Inverse] = 1 ),
    KEEPFILTERS ( Metric[TargetLogic] &amp;lt;&amp;gt; "n/a" )
)&lt;/LI-CODE&gt;
&lt;P&gt;I can't guarantee this exact DAX will work since I know very little about your model and how the tables are related but maybe you can massage it a bit where needed.&lt;/P&gt;</description>
      <pubDate>Sun, 26 Dec 2021 18:20:18 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/How-to-provide-the-right-row-context-using-an-existing-measure/m-p/2256085#M54452</guid>
      <dc:creator>AlexisOlson</dc:creator>
      <dc:date>2021-12-26T18:20:18Z</dc:date>
    </item>
    <item>
      <title>Re: How to provide the right row context using an existing measure</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/How-to-provide-the-right-row-context-using-an-existing-measure/m-p/2256104#M54455</link>
      <description>&lt;P&gt;Hello,&lt;BR /&gt;thanks for your ideas.&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;What are the main reasons why your solution is more efficient than mine?&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;Thanks&lt;/P&gt;</description>
      <pubDate>Sun, 26 Dec 2021 21:07:47 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/How-to-provide-the-right-row-context-using-an-existing-measure/m-p/2256104#M54455</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2021-12-26T21:07:47Z</dc:date>
    </item>
    <item>
      <title>Re: How to provide the right row context using an existing measure</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/How-to-provide-the-right-row-context-using-an-existing-measure/m-p/2257133#M54503</link>
      <description>&lt;P&gt;The main reason would be that I'm iterating over fewer rows of data. This also eliminates the SWITCH.&lt;/P&gt;</description>
      <pubDate>Mon, 27 Dec 2021 16:20:15 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/How-to-provide-the-right-row-context-using-an-existing-measure/m-p/2257133#M54503</guid>
      <dc:creator>AlexisOlson</dc:creator>
      <dc:date>2021-12-27T16:20:15Z</dc:date>
    </item>
    <item>
      <title>Re: How to provide the right row context using an existing measure</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/How-to-provide-the-right-row-context-using-an-existing-measure/m-p/2258865#M54573</link>
      <description>&lt;P&gt;Hi&amp;nbsp;Anonymous&lt;/LI-USER&gt;&amp;nbsp;,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Does the replies above solve your problem? If it has been solved, please mark the correct reply as the standard answer to help the other members find it more quickly.Thanks in advance for your kind cooperation!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Hope it helps,&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;Community Support Team _ Caitlyn&lt;/P&gt;
&lt;P&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;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 29 Dec 2021 01:16:22 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/How-to-provide-the-right-row-context-using-an-existing-measure/m-p/2258865#M54573</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2021-12-29T01:16:22Z</dc:date>
    </item>
  </channel>
</rss>

