<?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: Need help with a measure in a measure, dynamic age grouping - VERY slow... in DAX Commands and Tips</title>
    <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Need-help-with-a-measure-in-a-measure-dynamic-age-grouping-VERY/m-p/1664223#M33965</link>
    <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="javascript:void(0)" data-lia-user-mentions="" data-lia-user-uid="98044" data-lia-user-login="grggmrtn" class="lia-mention lia-mention-user"&gt;grggmrtn&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;After some testing in a dummy model at my end, below is a suggestion (contained in a single measure).&lt;/P&gt;
&lt;P&gt;This should at least be an improvement, but further optimization may be possible.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;How does it perform in your actual model?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Your requirements for the&amp;nbsp;&amp;nbsp;&lt;STRONG&gt;Antal borgere / alder&lt;/STRONG&gt;&amp;nbsp;measure are interesting as they are a combination of:&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;&lt;A href="https://www.daxpatterns.com/events-in-progress/" target="_blank" rel="noopener"&gt;Events in progress&lt;/A&gt;&lt;/LI&gt;
&lt;LI&gt;&lt;A href="https://www.daxpatterns.com/dynamic-segmentation/" target="_blank" rel="noopener"&gt;Dynamic segmentation&lt;/A&gt;&lt;/LI&gt;
&lt;LI&gt;&lt;A href="https://www.daxpatterns.com/related-distinct-count/" target="_blank" rel="noopener"&gt;Related distinct count&lt;/A&gt;&lt;/LI&gt;
&lt;/UL&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;Antal borgere / alder =
VAR StartDato =
    MIN ( Dato[Dato] )
VAR SlutDato =
    MAX ( Dato[Dato] )
VAR AldersGruppeMin =
    MIN ( Aldersgruppe[Min] )
VAR AldersGruppeMax =
    MAX ( Aldersgruppe[Max] )
RETURN
    CALCULATE (
        SUMX (
            SUMMARIZE (
                'VelfaerdBI v_FACT_Faelles_Aktivitet',
                'VelfaerdBI v_DIM_Borger'[CPR],
                'VelfaerdBI v_DIM_Borger'[Foedselsdato]
            ),
            VAR Alder =
                INT (
                    YEARFRAC (
                        'VelfaerdBI v_DIM_Borger'[Foedselsdato],
                        SlutDato
                    )
                )
            RETURN
                IF (
                    Alder &amp;gt;= AldersGruppeMin
                        &amp;amp;&amp;amp; Alder &amp;lt;= AldersGruppeMax,
                    1
                )
        ),
        'VelfaerdBI v_FACT_Faelles_Aktivitet'[StartDato] &amp;lt;= SlutDato,
        'VelfaerdBI v_FACT_Faelles_Aktivitet'[StopDato] &amp;gt;= StartDato
    )&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Your original measure was likely slow due in part to filtering of fact table in&amp;nbsp;&lt;STRONG&gt;Antal Borgere &lt;/STRONG&gt;and repeated context transition due to nested measure calls (there is an overhead associated with this).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Oh and I would suggest changing the Max of the "&amp;lt;26" group to 25, to avoid overlapping groups.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Possible further improvements I'm thinking of:&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;Define date bounds based AldersGruppeMin and AldresGruppeMax, to avoid repeated YEARFRAC calculations&lt;/LI&gt;
&lt;LI&gt;Include a row count in SUMMARIZE, rather than CPR&lt;/LI&gt;
&lt;/UL&gt;
&lt;P&gt;Regards,&lt;/P&gt;
&lt;P&gt;Owen&lt;/P&gt;</description>
    <pubDate>Sat, 13 Feb 2021 02:49:11 GMT</pubDate>
    <dc:creator>OwenAuger</dc:creator>
    <dc:date>2021-02-13T02:49:11Z</dc:date>
    <item>
      <title>Need help with a measure in a measure, dynamic age grouping - VERY slow...</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Need-help-with-a-measure-in-a-measure-dynamic-age-grouping-VERY/m-p/1662292#M33903</link>
      <description>&lt;P&gt;Just to start, what I'm doing here &lt;EM&gt;works&lt;/EM&gt;, it's just REALLY slow and I'm wondering if there's anything I can do to make it faster.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have a list of about 9000 people in a dimension with ID (CPR) and Birthday (Foedselsdato). I need to make a line graph, where I show the number of people that are in diverse age groups by month - meaning age groups during the month (dynamic age).&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;First measure: Number of people with an active service in the chosen time period (or time period on an axis). The active service is if it's between the start date and stop date:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;Antal Borgere = 
VAR StartDato =
    MIN ( Dato[Dato] )
VAR SlutDato =
    MAX ( Dato[Dato] )
RETURN
CALCULATE(
    DISTINCTCOUNT('VelfaerdBI v_DIM_Borger'[CPR]),
        FILTER(
            'VelfaerdBI v_FACT_Faelles_Aktivitet', 
            'VelfaerdBI v_FACT_Faelles_Aktivitet'[StartDato] &amp;lt;= SlutDato &amp;amp;&amp;amp; 
            'VelfaerdBI v_FACT_Faelles_Aktivitet'[StopDato] &amp;gt;= StartDato 
            )
    )&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;Second measure: Age (at the time of the date filter):&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;Alder = 
INT(
    YEARFRAC(
        MAX('VelfaerdBI v_DIM_Borger'[Foedselsdato]),
        MAX(Dato[Dato])
))&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Detached Age group (aldersgruppe) table:&lt;/P&gt;&lt;P&gt;&lt;img /&gt;&lt;/P&gt;&lt;P&gt;Third measure: number of people per age group:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;Antal borgere / alder = 
CALCULATE(
    [Antal Borgere],
    FILTER(
        'VelfaerdBI v_DIM_Borger',
        COUNTROWS(
            FILTER(
                AldersGruppe,
                [Alder] &amp;gt;= AldersGruppe[Min] &amp;amp;&amp;amp; [Alder] &amp;lt;= AldersGruppe[Max]
            )
        )
    )
)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;My line graph has Year/Month as axis, the third measure as value, and AldersGruppe as Legend.&lt;/P&gt;&lt;P&gt;It works perfectly.&lt;/P&gt;&lt;P&gt;&lt;img /&gt;&lt;/P&gt;&lt;P&gt;But it takes 10 minutes to show data when the report is loaded. Not to mention the time it takes when the user starts clicking the slicers I have on the page.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Is there anything you all can think of that would help me calculate this quicker?&lt;/P&gt;</description>
      <pubDate>Fri, 12 Feb 2021 07:45:12 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Need-help-with-a-measure-in-a-measure-dynamic-age-grouping-VERY/m-p/1662292#M33903</guid>
      <dc:creator>grggmrtn</dc:creator>
      <dc:date>2021-02-12T07:45:12Z</dc:date>
    </item>
    <item>
      <title>Re: Need help with a measure in a measure, dynamic age grouping - VERY slow...</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Need-help-with-a-measure-in-a-measure-dynamic-age-grouping-VERY/m-p/1664223#M33965</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="javascript:void(0)" data-lia-user-mentions="" data-lia-user-uid="98044" data-lia-user-login="grggmrtn" class="lia-mention lia-mention-user"&gt;grggmrtn&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;After some testing in a dummy model at my end, below is a suggestion (contained in a single measure).&lt;/P&gt;
&lt;P&gt;This should at least be an improvement, but further optimization may be possible.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;How does it perform in your actual model?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Your requirements for the&amp;nbsp;&amp;nbsp;&lt;STRONG&gt;Antal borgere / alder&lt;/STRONG&gt;&amp;nbsp;measure are interesting as they are a combination of:&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;&lt;A href="https://www.daxpatterns.com/events-in-progress/" target="_blank" rel="noopener"&gt;Events in progress&lt;/A&gt;&lt;/LI&gt;
&lt;LI&gt;&lt;A href="https://www.daxpatterns.com/dynamic-segmentation/" target="_blank" rel="noopener"&gt;Dynamic segmentation&lt;/A&gt;&lt;/LI&gt;
&lt;LI&gt;&lt;A href="https://www.daxpatterns.com/related-distinct-count/" target="_blank" rel="noopener"&gt;Related distinct count&lt;/A&gt;&lt;/LI&gt;
&lt;/UL&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;Antal borgere / alder =
VAR StartDato =
    MIN ( Dato[Dato] )
VAR SlutDato =
    MAX ( Dato[Dato] )
VAR AldersGruppeMin =
    MIN ( Aldersgruppe[Min] )
VAR AldersGruppeMax =
    MAX ( Aldersgruppe[Max] )
RETURN
    CALCULATE (
        SUMX (
            SUMMARIZE (
                'VelfaerdBI v_FACT_Faelles_Aktivitet',
                'VelfaerdBI v_DIM_Borger'[CPR],
                'VelfaerdBI v_DIM_Borger'[Foedselsdato]
            ),
            VAR Alder =
                INT (
                    YEARFRAC (
                        'VelfaerdBI v_DIM_Borger'[Foedselsdato],
                        SlutDato
                    )
                )
            RETURN
                IF (
                    Alder &amp;gt;= AldersGruppeMin
                        &amp;amp;&amp;amp; Alder &amp;lt;= AldersGruppeMax,
                    1
                )
        ),
        'VelfaerdBI v_FACT_Faelles_Aktivitet'[StartDato] &amp;lt;= SlutDato,
        'VelfaerdBI v_FACT_Faelles_Aktivitet'[StopDato] &amp;gt;= StartDato
    )&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Your original measure was likely slow due in part to filtering of fact table in&amp;nbsp;&lt;STRONG&gt;Antal Borgere &lt;/STRONG&gt;and repeated context transition due to nested measure calls (there is an overhead associated with this).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Oh and I would suggest changing the Max of the "&amp;lt;26" group to 25, to avoid overlapping groups.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Possible further improvements I'm thinking of:&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;Define date bounds based AldersGruppeMin and AldresGruppeMax, to avoid repeated YEARFRAC calculations&lt;/LI&gt;
&lt;LI&gt;Include a row count in SUMMARIZE, rather than CPR&lt;/LI&gt;
&lt;/UL&gt;
&lt;P&gt;Regards,&lt;/P&gt;
&lt;P&gt;Owen&lt;/P&gt;</description>
      <pubDate>Sat, 13 Feb 2021 02:49:11 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Need-help-with-a-measure-in-a-measure-dynamic-age-grouping-VERY/m-p/1664223#M33965</guid>
      <dc:creator>OwenAuger</dc:creator>
      <dc:date>2021-02-13T02:49:11Z</dc:date>
    </item>
    <item>
      <title>Re: Need help with a measure in a measure, dynamic age grouping - VERY slow...</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Need-help-with-a-measure-in-a-measure-dynamic-age-grouping-VERY/m-p/1670729#M34163</link>
      <description>&lt;P&gt;Hey &lt;a href="javascript:void(0)" data-lia-user-mentions="" data-lia-user-uid="6799" data-lia-user-login="OwenAuger" class="lia-mention lia-mention-user"&gt;OwenAuger&lt;/a&gt; your solution is actually pretty amazing. I just plugged it in to our solution and it's crazy fast, just what I needed!&lt;/P&gt;&lt;P&gt;But thanks for the explanation as well - that's going to help me a LOT in the future &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 17 Feb 2021 04:41:53 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Need-help-with-a-measure-in-a-measure-dynamic-age-grouping-VERY/m-p/1670729#M34163</guid>
      <dc:creator>grggmrtn</dc:creator>
      <dc:date>2021-02-17T04:41:53Z</dc:date>
    </item>
    <item>
      <title>Re: Need help with a measure in a measure, dynamic age grouping - VERY slow...</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Need-help-with-a-measure-in-a-measure-dynamic-age-grouping-VERY/m-p/1672650#M34206</link>
      <description>&lt;P&gt;Hey&amp;nbsp;&lt;a href="javascript:void(0)" data-lia-user-mentions="" data-lia-user-uid="98044" data-lia-user-login="grggmrtn" class="lia-mention lia-mention-user"&gt;grggmrtn&lt;/a&gt;&amp;nbsp;- you're very welcome, and I'm glad to hear it worked well with your actual dataset!&lt;/P&gt;
&lt;P&gt;All the best &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;Owen&lt;/P&gt;</description>
      <pubDate>Wed, 17 Feb 2021 20:05:03 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Need-help-with-a-measure-in-a-measure-dynamic-age-grouping-VERY/m-p/1672650#M34206</guid>
      <dc:creator>OwenAuger</dc:creator>
      <dc:date>2021-02-17T20:05:03Z</dc:date>
    </item>
  </channel>
</rss>

