<?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: Calculating an INDEX via a measure in DAX Commands and Tips</title>
    <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Calculating-an-INDEX-via-a-measure/m-p/2497704#M68962</link>
    <description>&lt;P&gt;Hi&amp;nbsp;Anonymous&lt;/LI-USER&gt;&amp;nbsp;,&lt;/P&gt;
&lt;P&gt;Is your problem solved?? If so, Would you mind accept the helpful replies as solutions? Then we are able to close the thread. More people who have the same requirement will find the solution quickly and benefit here. Thank you.&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Best Regards,&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Community Support Team _ kalyj&lt;/SPAN&gt;&lt;/P&gt;</description>
    <pubDate>Fri, 06 May 2022 06:19:09 GMT</pubDate>
    <dc:creator>v-yanjiang-msft</dc:creator>
    <dc:date>2022-05-06T06:19:09Z</dc:date>
    <item>
      <title>Calculating an INDEX via a measure</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Calculating-an-INDEX-via-a-measure/m-p/2442388#M65450</link>
      <description>&lt;P&gt;I need to calculate an Index score for each individual in our dataset based on the number of historical transactions. I have been able to calculate this score in a calculated column, but I need need to do the calculation in a measure so we can also calculate the index for dates in the past (rolling). For now, I only focus on calculating today's values, because I want to get that working first.&lt;BR /&gt;&lt;BR /&gt;What do I need to convert this calculation into a measure, so it calculates the value for each individual?&lt;BR /&gt;&lt;BR /&gt;---&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;Engagement Index = 

VAR NumberTransactionsLastYear = 
    CALCULATE(
        COUNTROWS('Transaction by Destination'),
        FILTER('Transaction by Destination', Individuals[contactid] = 'Transaction by Destination'[_od_individual_value] &amp;amp;&amp;amp;
                                             RELATED(Transactions[Transaction Date]) &amp;gt;= Date(YEAR(TODAY())-1, MONTH(TODAY()), DAY(TODAY())) &amp;amp;&amp;amp;
                                             RELATED(Transactions[Transaction Date]) &amp;lt; TODAY()
        )
    )

VAR NumberTransactionsTwoYearsBack = 
    CALCULATE(
        COUNTROWS('Transaction by Destination'),
        FILTER('Transaction by Destination', Individuals[contactid] = 'Transaction by Destination'[_od_individual_value] &amp;amp;&amp;amp;
                                             RELATED(Transactions[Transaction Date]) &amp;gt;= DATE(YEAR(TODAY()), MONTH(TODAY())-24, DAY(TODAY())) &amp;amp;&amp;amp;
                                             RELATED(Transactions[Transaction Date]) &amp;lt; DATE(YEAR(TODAY()), MONTH(TODAY())-12, DAY(TODAY()))
        )
    )

VAR NumberTransactionsThreeYearsBack = 
    CALCULATE(
        COUNTROWS('Transaction by Destination'),
        FILTER('Transaction by Destination', Individuals[contactid] = 'Transaction by Destination'[_od_individual_value] &amp;amp;&amp;amp;
                                             RELATED(Transactions[Transaction Date]) &amp;gt;= DATE(YEAR(TODAY()), MONTH(TODAY())-36, DAY(TODAY())) &amp;amp;&amp;amp;
                                             RELATED(Transactions[Transaction Date]) &amp;lt; DATE(YEAR(TODAY()), MONTH(TODAY())-24, DAY(TODAY()))
        )
    )

VAR NumberTransactionsFourYearsBack = 
    CALCULATE(
        COUNTROWS('Transaction by Destination'),
        FILTER('Transaction by Destination', Individuals[contactid] = 'Transaction by Destination'[_od_individual_value] &amp;amp;&amp;amp;
                                             RELATED(Transactions[Transaction Date]) &amp;gt;= DATE(YEAR(TODAY()), MONTH(TODAY())-48, DAY(TODAY())) &amp;amp;&amp;amp;
                                             RELATED(Transactions[Transaction Date]) &amp;lt; DATE(YEAR(TODAY()), MONTH(TODAY())-36, DAY(TODAY()))
        )
    )

VAR NumberTransactionsHistory = 
    CALCULATE(
        COUNTROWS('Transaction by Destination'),
        FILTER('Transaction by Destination', Individuals[contactid] = 'Transaction by Destination'[_od_individual_value] &amp;amp;&amp;amp;
                                             RELATED(Transactions[Transaction Date]) &amp;lt; DATE(YEAR(TODAY()), MONTH(TODAY())-48, DAY(TODAY()))
        )
    )

VAR DEIID = 
    (IF(NumberTransactionsLastYear &amp;lt;&amp;gt; 0, 16, 0)) +
    (IF(NumberTransactionsTwoYearsBack &amp;lt;&amp;gt; 0, 8, 0)) +
    (IF(NumberTransactionsThreeYearsBack &amp;lt;&amp;gt; 0, 4, 0)) +
    (IF(NumberTransactionsFourYearsBack &amp;lt;&amp;gt; 0, 2, 0)) + 
    (IF(NumberTransactionsHistory &amp;lt;&amp;gt; 0, 1, 0)) 

VAR INDEX =
    SWITCH(DEIID,
    0,0,
    1,-8,
    2,-7,
    3,-7,
    4,-6,
    5,-6,
    6,-5,
    7,-5,
    8,-4,
    9,-4,
    10,-3,
    11,-3,
    12,-2,
    13,-2,
    14,-1,
    15,-1,
    16,1,
    17,2,
    18,3,
    19,3,
    20,4,
    21,4,
    22,5,
    23,5,
    24,6,
    25,6,
    26,7,
    27,7,
    28,8,
    29,8,
    30,9,
    31,9
)

RETURN
    INDEX&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;---&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 07 Apr 2022 06:56:53 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Calculating-an-INDEX-via-a-measure/m-p/2442388#M65450</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2022-04-07T06:56:53Z</dc:date>
    </item>
    <item>
      <title>Re: Calculating an INDEX via a measure</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Calculating-an-INDEX-via-a-measure/m-p/2444375#M65558</link>
      <description>&lt;P&gt;Since you don't have row context, you need to use an aggregator like VALUES or MAX to grab the Individuals[contactid].&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I'd try something like this:&lt;/P&gt;
&lt;LI-CODE lang="php"&gt;Engagement Index =
VAR _Today = TODAY ()
VAR _1 = DATE ( YEAR ( _Today ) - 1, MONTH ( _Today ), DAY ( _Today ) )
VAR _2 = DATE ( YEAR ( _Today ) - 2, MONTH ( _Today ), DAY ( _Today ) )
VAR _3 = DATE ( YEAR ( _Today ) - 3, MONTH ( _Today ), DAY ( _Today ) )
VAR _4 = DATE ( YEAR ( _Today ) - 4, MONTH ( _Today ), DAY ( _Today ) )
VAR _Individuals =
    TREATAS (
        VALUES ( Individuals[contactid] ),
        'Transaction by Destination'[_od_individual_value]
    )
VAR NumberTransactionsLastYear =
    CALCULATE (
        COUNTROWS ( 'Transaction by Destination' ),
        KEEPFILTERS ( _Individuals ),
        Transactions[Transaction Date] &amp;gt;= _1,
        Transactions[Transaction Date] &amp;lt; _Today
    )
VAR NumberTransactionsTwoYearsBack =
    CALCULATE (
        COUNTROWS ( 'Transaction by Destination' ),
        KEEPFILTERS ( _Individuals ),
        Transactions[Transaction Date] &amp;gt;= _2,
        Transactions[Transaction Date] &amp;lt; _1
    )
VAR NumberTransactionsThreeYearsBack =
    CALCULATE (
        COUNTROWS ( 'Transaction by Destination' ),
        KEEPFILTERS ( _Individuals ),
        Transactions[Transaction Date] &amp;gt;= _3,
        Transactions[Transaction Date] &amp;lt; _2
    )
VAR NumberTransactionsFourYearsBack =
    CALCULATE (
        COUNTROWS ( 'Transaction by Destination' ),
        KEEPFILTERS ( _Individuals ),
        Transactions[Transaction Date] &amp;gt;= _4,
        Transactions[Transaction Date] &amp;lt; _3
    )
VAR NumberTransactionsHistory =
    CALCULATE (
        COUNTROWS ( 'Transaction by Destination' ),
        KEEPFILTERS ( _Individuals ),
        Transactions[Transaction Date] &amp;lt; _4
    )
VAR DEIID =
    IF ( NumberTransactionsLastYear             &amp;gt; 0, 16, 0 )
        + IF ( NumberTransactionsTwoYearsBack   &amp;gt; 0, 8,  0 )
        + IF ( NumberTransactionsThreeYearsBack &amp;gt; 0, 4,  0 )
        + IF ( NumberTransactionsFourYearsBack  &amp;gt; 0, 2,  0 )
        + IF ( NumberTransactionsHistory        &amp;gt; 0, 1,  0 )
VAR INDEX =
    SWITCH (
        DEIID,
        0,  0,
        1,  -8,
        2,  -7,
        3,  -7,
        4,  -6,
        5,  -6,
        6,  -5,
        7,  -5,
        8,  -4,
        9,  -4,
        10, -3,
        11, -3,
        12, -2,
        13, -2,
        14, -1,
        15, -1,
        16,  1,
        17,  2,
        18,  3,
        19,  3,
        20,  4,
        21,  4,
        22,  5,
        23,  5,
        24,  6,
        25,  6,
        26,  7,
        27,  7,
        28,  8,
        29,  8,
        30,  9,
        31,  9
    )
RETURN
    INDEX&lt;/LI-CODE&gt;</description>
      <pubDate>Thu, 07 Apr 2022 20:47:18 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Calculating-an-INDEX-via-a-measure/m-p/2444375#M65558</guid>
      <dc:creator>AlexisOlson</dc:creator>
      <dc:date>2022-04-07T20:47:18Z</dc:date>
    </item>
    <item>
      <title>Re: Calculating an INDEX via a measure</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Calculating-an-INDEX-via-a-measure/m-p/2445178#M65598</link>
      <description>&lt;P&gt;Thanks for your help and for cleaning the code &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt; Unfortunately, this is not resulting in what I am looking for. I would like to be able to group the number of individuals based on their index number. This works when I use a calculated column (left table), but not when I use the measure. However, when I use the measure in the table together with contactid, it shows the right index per contactid. So the calculation works for individual rows, but I am not able to do groupings, etc.&lt;/P&gt;&lt;P&gt;&lt;img /&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 08 Apr 2022 07:23:59 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Calculating-an-INDEX-via-a-measure/m-p/2445178#M65598</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2022-04-08T07:23:59Z</dc:date>
    </item>
    <item>
      <title>Re: Calculating an INDEX via a measure</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Calculating-an-INDEX-via-a-measure/m-p/2446321#M65661</link>
      <description>&lt;P&gt;Ah, I see. Yes, this is much easier with a calculated column.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;To do this with measures, you'll need to create a new dimension table for the index to use on the matrix rows and then write a measure that counts the number of individuals that fall into each index bucket.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Something like this for example:&lt;/P&gt;
&lt;LI-CODE lang="php"&gt;Number of Individuals =
VAR _Indices_ = VALUES ( dimIndex[Index] )
VAR _Individuals_ =
    ADDCOLUMNS (
        VALUES ( Individuals[contactid] ),
        "@Engagement", [Engagement Index]
    )
VAR _Filtered_ = FILTER ( _Individuals_, [@Engagement] IN _Indices_ )
RETURN
    COUNTROWS ( _Filtered_ )&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Here are some other related patterns:&lt;/P&gt;
&lt;P&gt;&lt;A href="https://www.daxpatterns.com/dynamic-segmentation/" target="_blank"&gt;https://www.daxpatterns.com/dynamic-segmentation/&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 08 Apr 2022 14:52:50 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Calculating-an-INDEX-via-a-measure/m-p/2446321#M65661</guid>
      <dc:creator>AlexisOlson</dc:creator>
      <dc:date>2022-04-08T14:52:50Z</dc:date>
    </item>
    <item>
      <title>Re: Calculating an INDEX via a measure</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Calculating-an-INDEX-via-a-measure/m-p/2497704#M68962</link>
      <description>&lt;P&gt;Hi&amp;nbsp;Anonymous&lt;/LI-USER&gt;&amp;nbsp;,&lt;/P&gt;
&lt;P&gt;Is your problem solved?? If so, Would you mind accept the helpful replies as solutions? Then we are able to close the thread. More people who have the same requirement will find the solution quickly and benefit here. Thank you.&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Best Regards,&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Community Support Team _ kalyj&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 06 May 2022 06:19:09 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Calculating-an-INDEX-via-a-measure/m-p/2497704#M68962</guid>
      <dc:creator>v-yanjiang-msft</dc:creator>
      <dc:date>2022-05-06T06:19:09Z</dc:date>
    </item>
  </channel>
</rss>

