<?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: Can not calculate the running total with RANK function? in DAX Commands and Tips</title>
    <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Can-not-calculate-the-running-total-with-RANK-function/m-p/3364907#M126522</link>
    <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="javascript:void(0)" data-lia-user-mentions="" data-lia-user-uid="591285" data-lia-user-login="Yiyi" class="lia-mention lia-mention-user"&gt;Yiyi&lt;/a&gt;&amp;nbsp;,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;According to your statement, I think [Unique_Item_Count] should be a column in your virtual table. So we couldn't use it directly in CALCULATE() without any&amp;nbsp;aggregation.&lt;/P&gt;
&lt;P&gt;Measure:&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;Pareto Test =
VAR Total_Unique_Item =
    CALCULATE (
        DISTINCTCOUNT ( 'Main Data'[HeadlineID] ),
        ALLSELECTED ( 'Main Data' )
    )
VAR SummarizedTable =
    SUMMARIZE (
        ALLSELECTED ( 'Main Data' ),
        'Main Data'[Media],
        "Unique_Item_Count", DISTINCTCOUNT ( 'Main Data'[HeadlineID] )
    )
VAR Summarizedtable_with_ranking =
    ADDCOLUMNS (
        SummarizedTable,
        "Rank",
            RANK (
                DENSE,
                SummarizedTable,
                ORDERBY ( [Unique_Item_Count], DESC, 'Main Data'[Media], ASC ),
                DEFAULT
            )
    )
VAR CumulativeSum =
    SUMX (
        FILTER (
            Summarizedtable_with_ranking,
            [Rank]
                &amp;lt;= MAXX (
                    FILTER ( Summarizedtable_with_ranking, [Media] = MAX ( 'Main Data'[Media] ) ),
                    [Rank]
                )
        ),
        [Unique_Item_Count]
    )
RETURN
    DIVIDE ( CumulativeSum, Total_Unique_Item )&lt;/LI-CODE&gt;
&lt;P&gt;Result is as below.&lt;/P&gt;
&lt;P&gt;&lt;img /&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Best Regards,&lt;BR /&gt;Rico Zhou&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&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>Fri, 04 Aug 2023 06:43:13 GMT</pubDate>
    <dc:creator>Anonymous</dc:creator>
    <dc:date>2023-08-04T06:43:13Z</dc:date>
    <item>
      <title>Can not calculate the running total with RANK function?</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Can-not-calculate-the-running-total-with-RANK-function/m-p/3361224#M126364</link>
      <description>&lt;P&gt;Hello all,&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have created a summazied table for each media with its unique item count. I added rank as well for the purpose of calculating running total ( many media have the same value thus using rank with distinct number can make sure all numbers are counted in running total).&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Dax for the new table:&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;New Table = 

VAR SummarizedTable= SUMMARIZE(
            ALLSELECTED('Main Data'),
            'Main Data'[Media],
            "Unique_Item_Count", DISTINCTCOUNT('Main Data'[HeadlineID])
        )
RETURN 
ADDCOLUMNS(
    SummarizedTable,
    "Rank",
    RANK (
    DENSE,
    SummarizedTable,
    ORDERBY ( [Unique_Item_Count], DESC, 'Main Data'[Media], ASC ),
    DEFAULT
)
)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The newly created table looks fine to me:&amp;nbsp;&lt;/P&gt;&lt;TABLE border="1"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;Media&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;Unique_Item_Count&lt;/TD&gt;&lt;TD&gt;Rank&amp;nbsp;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;Media 1&lt;/TD&gt;&lt;TD&gt;1233&lt;/TD&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;Media 2&lt;/TD&gt;&lt;TD&gt;744&lt;/TD&gt;&lt;TD&gt;2&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;Media 3&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;532&lt;/TD&gt;&lt;TD&gt;3&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;Media 4&lt;/TD&gt;&lt;TD&gt;132&lt;/TD&gt;&lt;TD&gt;4&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;Media 5&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;132&lt;/TD&gt;&lt;TD&gt;5&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;However, based on such logic, when I try to create a running total and the percentage of running total / total_unique_item, it just doesn't work.&lt;FONT color="#FF0000"&gt; The error message said that in VAR CumulativeSum that can not find the name [Unique_item_Count].&amp;nbsp;&lt;/FONT&gt;&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;Pareto Test = 
VAR Total_Unique_Item = 
    CALCULATE(
        DISTINCTCOUNT('Main Data'[HeadlineID]),
        ALLSELECTED('Main Data')
    )
VAR SummarizedTable = 
    SUMMARIZE(
    ALLSELECTED('Main Data'),
    'Main Data'[Media],
     "Unique_Item_Count", DISTINCTCOUNT('Main Data'[HeadlineID])
     )
VAR Summarizedtable_with_ranking = 
    ADDCOLUMNS(
    SummarizedTable,
    "Rank",
    RANK (
    DENSE,
    SummarizedTable,
    ORDERBY ( [Unique_Item_Count], DESC, 'Main Data'[Media], ASC ),
    DEFAULT)
)

VAR CumulativeSum = CALCULATE([Unique_Item_Count],FILTER(ALL(Summarizedtable_with_ranking),[Rank] &amp;lt;= MAXX(Summarizedtable_with_ranking, [Rank])))

RETURN 
CumulativeSum/Total_Unique_Item&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Can you help me to understand what went wrong? Thanks a lot for your help!&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 02 Aug 2023 07:34:16 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Can-not-calculate-the-running-total-with-RANK-function/m-p/3361224#M126364</guid>
      <dc:creator>Yiyi</dc:creator>
      <dc:date>2023-08-02T07:34:16Z</dc:date>
    </item>
    <item>
      <title>Re: Can not calculate the running total with RANK function?</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Can-not-calculate-the-running-total-with-RANK-function/m-p/3364907#M126522</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="javascript:void(0)" data-lia-user-mentions="" data-lia-user-uid="591285" data-lia-user-login="Yiyi" class="lia-mention lia-mention-user"&gt;Yiyi&lt;/a&gt;&amp;nbsp;,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;According to your statement, I think [Unique_Item_Count] should be a column in your virtual table. So we couldn't use it directly in CALCULATE() without any&amp;nbsp;aggregation.&lt;/P&gt;
&lt;P&gt;Measure:&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;Pareto Test =
VAR Total_Unique_Item =
    CALCULATE (
        DISTINCTCOUNT ( 'Main Data'[HeadlineID] ),
        ALLSELECTED ( 'Main Data' )
    )
VAR SummarizedTable =
    SUMMARIZE (
        ALLSELECTED ( 'Main Data' ),
        'Main Data'[Media],
        "Unique_Item_Count", DISTINCTCOUNT ( 'Main Data'[HeadlineID] )
    )
VAR Summarizedtable_with_ranking =
    ADDCOLUMNS (
        SummarizedTable,
        "Rank",
            RANK (
                DENSE,
                SummarizedTable,
                ORDERBY ( [Unique_Item_Count], DESC, 'Main Data'[Media], ASC ),
                DEFAULT
            )
    )
VAR CumulativeSum =
    SUMX (
        FILTER (
            Summarizedtable_with_ranking,
            [Rank]
                &amp;lt;= MAXX (
                    FILTER ( Summarizedtable_with_ranking, [Media] = MAX ( 'Main Data'[Media] ) ),
                    [Rank]
                )
        ),
        [Unique_Item_Count]
    )
RETURN
    DIVIDE ( CumulativeSum, Total_Unique_Item )&lt;/LI-CODE&gt;
&lt;P&gt;Result is as below.&lt;/P&gt;
&lt;P&gt;&lt;img /&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Best Regards,&lt;BR /&gt;Rico Zhou&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&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>Fri, 04 Aug 2023 06:43:13 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Can-not-calculate-the-running-total-with-RANK-function/m-p/3364907#M126522</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2023-08-04T06:43:13Z</dc:date>
    </item>
  </channel>
</rss>

