<?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 Custom Rounding in Quick Measures Gallery</title>
    <link>https://community.fabric.microsoft.com/t5/Quick-Measures-Gallery/Custom-Rounding/m-p/2989185#M938</link>
    <description>&lt;P&gt;This one came out of this thread:&amp;nbsp;&lt;A href="https://community.powerbi.com/t5/Desktop/How-to-do-custom-rounding-in-DAX/m-p/2988669" target="_blank"&gt;https://community.powerbi.com/t5/Desktop/How-to-do-custom-rounding-in-DAX/m-p/2988669&lt;/A&gt;. Basically, how to do custom rounding such that:&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;Round all numbers down&lt;/LI&gt;
&lt;LI&gt;Compute the number of digits missing from 100 after rounding (99, 98, etc.)&amp;nbsp;&lt;/LI&gt;
&lt;LI&gt;Round up the highest decimal places in order to ensure 100 total&lt;/LI&gt;
&lt;/UL&gt;
&lt;P&gt;This was the result.&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;Rounding = 
    VAR __Cat2 = MAX('Table'[Category2])
    VAR __Table = 
        GENERATE(
            SUMMARIZE(
                FILTER(ALLSELECTED('Table'), [Category2] = __Cat2),
                'Table'[Category1],'Table'[Category2],"Value",MAX([Percentage])),
                VAR __Value = [Value]
                VAR __RD = ROUNDDOWN(__Value,0)
                VAR __Decimal = __Value - __RD
            RETURN
                ROW(
                    "RD", __RD,
                    "Decimal", __Decimal
                )
        )
    VAR __MaxDecimal = MAXX(__Table,[Decimal])
    VAR __MaxCategory = MAXX(FILTER(__Table, [Decimal] = __MaxDecimal),[Category1])
    VAR __2ndMaxDecimal = MAXX(FILTER(__Table, [Category1] &amp;lt;&amp;gt; __MaxCategory), [Decimal])
    VAR __2ndMaxCategory = MAXX(FILTER(__Table, [Category1] &amp;lt;&amp;gt; __MaxCategory &amp;amp;&amp;amp; [Decimal] = __2ndMaxDecimal),[Category1])
    VAR __Category = MAX('Table'[Category1])
    VAR __SumDown = SUMX(__Table, [RD])
    VAR __Result = 
        SWITCH(__SumDown,
            99, 
                IF(
                    __Category = __MaxCategory, 
                    ROUNDUP(MAX([Percentage]),0), 
                    ROUNDDOWN(MAX([Percentage]),0)
                ),
            98, 
                IF(
                    __Category = __MaxCategory || __Category = __2ndMaxCategory, 
                    ROUNDUP(MAX([Percentage]),0), 
                    ROUNDDOWN(MAX([Percentage]),0)
                )
        )
RETURN
    __Result&lt;/LI-CODE&gt;
&lt;P&gt;&lt;SPAN class="reportid hidden"&gt;eyJrIjoiOGYyMTRmZDUtMmNmOC00ZjdmLTg1NzYtMzczMjMyMDYzYjQyIiwidCI6IjRhMDQyNzQzLTM3M2EtNDNkMi04MjdiLTAwM2Y0YzdiYTFlNSIsImMiOjN9&lt;/SPAN&gt;&lt;/P&gt;</description>
    <pubDate>Mon, 26 Dec 2022 19:26:42 GMT</pubDate>
    <dc:creator>Greg_Deckler</dc:creator>
    <dc:date>2022-12-26T19:26:42Z</dc:date>
    <item>
      <title>Custom Rounding</title>
      <link>https://community.fabric.microsoft.com/t5/Quick-Measures-Gallery/Custom-Rounding/m-p/2989185#M938</link>
      <description>&lt;P&gt;This one came out of this thread:&amp;nbsp;&lt;A href="https://community.powerbi.com/t5/Desktop/How-to-do-custom-rounding-in-DAX/m-p/2988669" target="_blank"&gt;https://community.powerbi.com/t5/Desktop/How-to-do-custom-rounding-in-DAX/m-p/2988669&lt;/A&gt;. Basically, how to do custom rounding such that:&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;Round all numbers down&lt;/LI&gt;
&lt;LI&gt;Compute the number of digits missing from 100 after rounding (99, 98, etc.)&amp;nbsp;&lt;/LI&gt;
&lt;LI&gt;Round up the highest decimal places in order to ensure 100 total&lt;/LI&gt;
&lt;/UL&gt;
&lt;P&gt;This was the result.&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;Rounding = 
    VAR __Cat2 = MAX('Table'[Category2])
    VAR __Table = 
        GENERATE(
            SUMMARIZE(
                FILTER(ALLSELECTED('Table'), [Category2] = __Cat2),
                'Table'[Category1],'Table'[Category2],"Value",MAX([Percentage])),
                VAR __Value = [Value]
                VAR __RD = ROUNDDOWN(__Value,0)
                VAR __Decimal = __Value - __RD
            RETURN
                ROW(
                    "RD", __RD,
                    "Decimal", __Decimal
                )
        )
    VAR __MaxDecimal = MAXX(__Table,[Decimal])
    VAR __MaxCategory = MAXX(FILTER(__Table, [Decimal] = __MaxDecimal),[Category1])
    VAR __2ndMaxDecimal = MAXX(FILTER(__Table, [Category1] &amp;lt;&amp;gt; __MaxCategory), [Decimal])
    VAR __2ndMaxCategory = MAXX(FILTER(__Table, [Category1] &amp;lt;&amp;gt; __MaxCategory &amp;amp;&amp;amp; [Decimal] = __2ndMaxDecimal),[Category1])
    VAR __Category = MAX('Table'[Category1])
    VAR __SumDown = SUMX(__Table, [RD])
    VAR __Result = 
        SWITCH(__SumDown,
            99, 
                IF(
                    __Category = __MaxCategory, 
                    ROUNDUP(MAX([Percentage]),0), 
                    ROUNDDOWN(MAX([Percentage]),0)
                ),
            98, 
                IF(
                    __Category = __MaxCategory || __Category = __2ndMaxCategory, 
                    ROUNDUP(MAX([Percentage]),0), 
                    ROUNDDOWN(MAX([Percentage]),0)
                )
        )
RETURN
    __Result&lt;/LI-CODE&gt;
&lt;P&gt;&lt;SPAN class="reportid hidden"&gt;eyJrIjoiOGYyMTRmZDUtMmNmOC00ZjdmLTg1NzYtMzczMjMyMDYzYjQyIiwidCI6IjRhMDQyNzQzLTM3M2EtNDNkMi04MjdiLTAwM2Y0YzdiYTFlNSIsImMiOjN9&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 26 Dec 2022 19:26:42 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Quick-Measures-Gallery/Custom-Rounding/m-p/2989185#M938</guid>
      <dc:creator>Greg_Deckler</dc:creator>
      <dc:date>2022-12-26T19:26:42Z</dc:date>
    </item>
  </channel>
</rss>

