<?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: Refer to calculated table in DAX Commands and Tips</title>
    <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Refer-to-calculated-table/m-p/2795658#M87836</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;Thank you again for your time to help me.&amp;nbsp;&lt;BR /&gt;In the example dataset I get the same results as you, however it should not reply only adults (18+), there are children in the selection. It apears to ignore the filter and uses the overall MAX of all the birth_years.&lt;BR /&gt;&lt;BR /&gt;Furthermore, If I use the exact same measure on my actual model which has a live connection to an analysis server I get the following error:&lt;BR /&gt;&lt;EM&gt;"Calculation error in measure 'MeasureTable'[AgeGroups BL]: A function 'MAXX' has been used in a True/False expression that is used as a table filter expression. This is not allowed."&lt;BR /&gt;&lt;BR /&gt;&lt;/EM&gt;I can also generate the error in the example dataset by adding a calculate around the MAXX function.&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;Kind Regards,&lt;/P&gt;&lt;P&gt;Marieke&lt;/P&gt;</description>
    <pubDate>Mon, 26 Sep 2022 08:29:48 GMT</pubDate>
    <dc:creator>MariekevdAkker</dc:creator>
    <dc:date>2022-09-26T08:29:48Z</dc:date>
    <item>
      <title>Refer to calculated table</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Refer-to-calculated-table/m-p/2770823#M86255</link>
      <description>&lt;P&gt;I use a live connection to a SSAS Tabular Model. Therefor I cannot use calculated columns.&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;The table factDataExport contains a row for each answer in a form.&amp;nbsp;&lt;BR /&gt;Each participant can have multiple baseline forms with a visit_date. The measure below calculates the number of baselines in each age group. Agegroups are defined in the AddCategories table.&amp;nbsp;&lt;/P&gt;&lt;P&gt;In the measure below I would like to replace TODAY() with the birth_year of the particpiant. These are available in the 'Birth_year_table' and can be related to the factDataExport by [Record_Name_GUID]. However I can't get the measure to refer to the Birth_Year_table.&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;I need the age of the participant as "visit_date" - "Birth_Year" wich are both stored on different rows in the same (factDataExport) table.&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;AgeGroups BL = 


var VarCode = SELECTEDVALUE('AddCategories'[QNAME])
var MinAge = MIN('AddCategories'[From])
var MaxAge = MIN('AddCategories'[To])


VAR BL_Form_Instance_ID =          
    CALCULATETABLE(
        VALUES(factDataExport[Form_Instance_ID])
        ,ALL(dimMetadata)
        ,dimMetadata[Field_Variable_Name]="Visit_Type"
        ,factDataExport[AnswerNumeric]=0 --=BL visit
        ,factDataExport[Report_Status] &amp;lt;&amp;gt; BLANK()
    )
  

VAR Birth_Year_table =
		ADDCOLUMNS(
            //Participant IDs
			CALCULATETABLE(VALUES(factDataExport[Record_Name_GUID]))
            // Birth_Year
			,"Birth_Year"
			,CALCULATE(
                MAX(factDataExport[AnswerNumeric])
                ,dimMetadata[Field_Variable_Name]="Birth_Year"
                ,ALL(dimMetadata)
                ,factDataExport[AnswerNumeric] &amp;lt;&amp;gt; BLANK()
            )
		)


Return
    CALCULATE(
        COUNTROWS(factDataExport)
        ,dimMetadata[Field_Variable_Name] = "Visit_Date"
        ,ALL(dimMetadata)
        ,TREATAS(BL_Form_Instance_ID,factDataExport[Form_Instance_ID])  --BL Visits
        ,INT ( YEARFRAC ( TODAY(), factDataExport[AnswerDate], 1 ) ) &amp;gt; MinAge
        ,INT ( YEARFRAC ( TODAY(), factDataExport[AnswerDate], 1 ) ) &amp;lt; MaxAge
        
    )
 


&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 15 Sep 2022 14:27:31 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Refer-to-calculated-table/m-p/2770823#M86255</guid>
      <dc:creator>MariekevdAkker</dc:creator>
      <dc:date>2022-09-15T14:27:31Z</dc:date>
    </item>
    <item>
      <title>Re: Refer to calculated table</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Refer-to-calculated-table/m-p/2772300#M86346</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="javascript:void(0)" data-lia-user-mentions="" data-lia-user-uid="382963" data-lia-user-login="MariekevdAkker" class="lia-mention lia-mention-user"&gt;MariekevdAkker&lt;/a&gt;&amp;nbsp;,&lt;/P&gt;
&lt;P&gt;You can update the formula of measure &lt;STRONG&gt;[AgeGroups BL]&lt;/STRONG&gt; as below and check if it can return your expected result...&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;AgeGroups BL =
VAR VarCode =
    SELECTEDVALUE ( 'AddCategories'[QNAME] )
VAR MinAge =
    MIN ( 'AddCategories'[From] )
VAR MaxAge =
    MIN ( 'AddCategories'[To] )
VAR BL_Form_Instance_ID =
    CALCULATETABLE (
        VALUES ( factDataExport[Form_Instance_ID] ),
        ALL ( dimMetadata ),
        dimMetadata[Field_Variable_Name] = "Visit_Type",
        factDataExport[AnswerNumeric] = 0 --=BL visit
        ,
        factDataExport[Report_Status] &amp;lt;&amp;gt; BLANK ()
    )
VAR Birth_Year_table =
    ADDCOLUMNS (
        //Participant IDs
        CALCULATETABLE ( VALUES ( factDataExport[Record_Name_GUID] ) ) // Birth_Year
        ,
        "Birth_Year",
            CALCULATE (
                MAX ( factDataExport[AnswerNumeric] ),
                dimMetadata[Field_Variable_Name] = "Birth_Year",
                ALL ( dimMetadata ),
                factDataExport[AnswerNumeric] &amp;lt;&amp;gt; BLANK ()
            )
    )
RETURN
    CALCULATE (
        COUNTROWS ( factDataExport ),
        dimMetadata[Field_Variable_Name] = "Visit_Date",
        ALL ( dimMetadata ),
        TREATAS ( BL_Form_Instance_ID, factDataExport[Form_Instance_ID] ) --BL Visits
        ,
        INT (
            YEARFRAC (
                MAXX (
                    FILTER (
                        Birth_Year_table,
                        [Record_Name_GUID] = factDataExport[Record_Name_GUID]
                    ),
                    [Birth_Year]
                ),
                factDataExport[AnswerDate],
                1
            )
        ) &amp;gt; MinAge,
        INT (
            YEARFRAC (
                MAXX (
                    FILTER (
                        Birth_Year_table,
                        [Record_Name_GUID] = factDataExport[Record_Name_GUID]
                    ),
                    [Birth_Year]
                ),
                factDataExport[AnswerDate],
                1
            )
        ) &amp;lt; MaxAge
    )&lt;/LI-CODE&gt;
&lt;P&gt;If the above one can't help you get the desired result, please provide some&amp;nbsp;&lt;STRONG&gt;sample data&lt;/STRONG&gt;&amp;nbsp;in your tables (&lt;STRONG&gt;&lt;EM&gt;exclude&amp;nbsp;&lt;/EM&gt;&lt;/STRONG&gt;&lt;EM&gt;&lt;STRONG&gt;sensitive&amp;nbsp;&lt;/STRONG&gt;&lt;/EM&gt;&lt;STRONG&gt;&lt;EM&gt;data&lt;/EM&gt;&lt;/STRONG&gt;) with&amp;nbsp;&lt;FONT color="#FF0000"&gt;&lt;STRONG&gt;Text&lt;/STRONG&gt;&amp;nbsp;&lt;/FONT&gt;format and your&amp;nbsp;&lt;STRONG&gt;expected result&lt;/STRONG&gt;&amp;nbsp;with backend logic and special examples.&lt;FONT color="#FF0000"&gt;&amp;nbsp;&lt;STRONG&gt;It is better&lt;/STRONG&gt;&lt;/FONT&gt;&amp;nbsp;if you can share a&amp;nbsp;&lt;FONT color="#008000"&gt;&lt;STRONG&gt;simplified&lt;/STRONG&gt;&amp;nbsp;&lt;/FONT&gt;pbix file. You can refer the following link to upload the file to the community. Thank you.&lt;/P&gt;
&lt;P&gt;&lt;A href="https://nam06.safelinks.protection.outlook.com/?url=https%3A%2F%2Fcommunity.powerbi.com%2Ft5%2FDesktop%2FHow-to-upload-PBI-in-Community%2Fm-p%2F1672886&amp;amp;data=04%7C01%7Cv-yiruan%40microsoft.com%7C4f580813734d4a8355b008da16f6e91a%7C72f988bf86f141af91ab2d7cd011db47%7C1%7C0%7C637847547341062885%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C1000&amp;amp;sdata=YJvujige2YITXKbKED9JieQm5LBdf%2F3IYPM4ggdiijQ%3D&amp;amp;reserved=0" target="_blank"&gt;How to upload PBI in Community&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;Best Regards&lt;/P&gt;</description>
      <pubDate>Fri, 16 Sep 2022 05:42:49 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Refer-to-calculated-table/m-p/2772300#M86346</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2022-09-16T05:42:49Z</dc:date>
    </item>
    <item>
      <title>Re: Refer to calculated table</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Refer-to-calculated-table/m-p/2776844#M86712</link>
      <description>&lt;P&gt;Thank you for your answer, I get the following error:&lt;BR /&gt;&lt;EM&gt;"Calculation error in measure 'MeasureTable'[AgeGroups BL]: A function 'MAXX' has been used in a True/False expression that is used as a table filter expression. This is not allowed."&lt;BR /&gt;&lt;BR /&gt;&lt;/EM&gt;Anonymous&lt;/a&gt;&amp;nbsp;I have uploaded a pbx here:&amp;nbsp;&lt;A href="https://www.dropbox.com/scl/fo/4luwg5foue4gp7ed4zijc/h?dl=0&amp;amp;rlkey=ckoaywuuo09h1nj8a8c4s8xi3" target="_blank" rel="noopener"&gt;Dropbox&lt;/A&gt;&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 19 Sep 2022 09:34:24 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Refer-to-calculated-table/m-p/2776844#M86712</guid>
      <dc:creator>MariekevdAkker</dc:creator>
      <dc:date>2022-09-19T09:34:24Z</dc:date>
    </item>
    <item>
      <title>Re: Refer to calculated table</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Refer-to-calculated-table/m-p/2782551#M87098</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="javascript:void(0)" data-lia-user-mentions="" data-lia-user-uid="382963" data-lia-user-login="MariekevdAkker" class="lia-mention lia-mention-user"&gt;MariekevdAkker&lt;/a&gt;&amp;nbsp;,&lt;/P&gt;
&lt;P&gt;I tried to update the formula of the measure&lt;STRONG&gt; &lt;EM&gt;[AgeGroups BL]&lt;/EM&gt; &lt;/STRONG&gt;using the formula in my previous post, it works welll. Please find the details in the screenshot below. Is there anything else I missing here?&lt;/P&gt;
&lt;P&gt;&lt;img /&gt;&lt;/P&gt;
&lt;P&gt;Best Regards&lt;/P&gt;</description>
      <pubDate>Wed, 21 Sep 2022 03:23:50 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Refer-to-calculated-table/m-p/2782551#M87098</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2022-09-21T03:23:50Z</dc:date>
    </item>
    <item>
      <title>Re: Refer to calculated table</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Refer-to-calculated-table/m-p/2795658#M87836</link>
      <description>&lt;P&gt;Hi&amp;nbsp;Anonymous&lt;/a&gt;&amp;nbsp;,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you again for your time to help me.&amp;nbsp;&lt;BR /&gt;In the example dataset I get the same results as you, however it should not reply only adults (18+), there are children in the selection. It apears to ignore the filter and uses the overall MAX of all the birth_years.&lt;BR /&gt;&lt;BR /&gt;Furthermore, If I use the exact same measure on my actual model which has a live connection to an analysis server I get the following error:&lt;BR /&gt;&lt;EM&gt;"Calculation error in measure 'MeasureTable'[AgeGroups BL]: A function 'MAXX' has been used in a True/False expression that is used as a table filter expression. This is not allowed."&lt;BR /&gt;&lt;BR /&gt;&lt;/EM&gt;I can also generate the error in the example dataset by adding a calculate around the MAXX function.&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;Kind Regards,&lt;/P&gt;&lt;P&gt;Marieke&lt;/P&gt;</description>
      <pubDate>Mon, 26 Sep 2022 08:29:48 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Refer-to-calculated-table/m-p/2795658#M87836</guid>
      <dc:creator>MariekevdAkker</dc:creator>
      <dc:date>2022-09-26T08:29:48Z</dc:date>
    </item>
    <item>
      <title>Re: Refer to calculated table</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Refer-to-calculated-table/m-p/3314123#M123953</link>
      <description>&lt;P&gt;Hi&amp;nbsp;Anonymous&lt;/a&gt;,&lt;/P&gt;&lt;P&gt;This is long overdue but I finally found the solution.&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;The measure that eventually worked is:&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;AGE GROUPS per BIODAYMED = 
VAR x =
CALCULATETABLE (
        ADDCOLUMNS(
            SUMMARIZE (
                factAnswer,
                factAnswer[Participant_GUID],
                factAnswer[Form_Instance_ID]
            )
            ,"BirthYear",
                    DATE ( CALCULATE (
                        MIN ( factAnswer[AnswerNumeric] ),
                        dimMetadata[Field_Variable_Name] = "Birth_Year",
                        ALL ( factAnswer[Form_Instance_ID] )
                    ), 1, 1 ),
                "VisitDate",
                    CALCULATE (
                        MIN ( factAnswer[AnswerDateDate] ),
                        dimMetadata[Field_Variable_Name] = "Visit_Date"
                    ),
                "VisitType",
                    CALCULATE (
                        MIN ( factAnswer[Answer] ),
                        dimMetadata[Field_Variable_Name] = "Visit_Type"
                    ),
                "AgeAtVisit",
                    DATEDIFF (
                        DATE ( CALCULATE (
                            MIN ( factAnswer[AnswerNumeric] ),
                            dimMetadata[Field_Variable_Name] = "Birth_Year",
                            ALL ( factAnswer[Form_Instance_ID] )
                        ), 1, 1 ),
                        CALCULATE (
                            MIN ( factAnswer[AnswerDateDate] ),
                            dimMetadata[Field_Variable_Name] = "Visit_Date"
                        ),
                        YEAR
                    ),
                "Medication",
                    CALCULATE (
                        MIN ( factAnswer[Answer] ),
                        dimMetadata[Field_Variable_Name] = "BioDayMed_Type"
                    )
            )
            
            )


    VAR MinAge = SELECTEDVALUE(AddCategories[From],0.01)
    VAR MaxAge = SELECTEDVALUE(AddCategories[To],150)
    VAR Med = CONVERT(SELECTEDVALUE(WhatIf[Value]),STRING)
    VAR VisitType = "0"

    VAR CountMedAgeGroup = COUNTX (
            FILTER (x, [AgeAtVisit]&amp;gt;=MinAge &amp;amp;&amp;amp; [AgeAtVisit]&amp;lt;=MaxAge &amp;amp;&amp;amp; [Medication] = Med &amp;amp;&amp;amp; [VisitType] = VisitType ),
            [Form_Instance_ID]
        )

   
   VAR NoSelectedMed = COUNTX (
            FILTER (x, [AgeAtVisit]&amp;gt;=MinAge &amp;amp;&amp;amp; [AgeAtVisit]&amp;lt;=MaxAge &amp;amp;&amp;amp; [VisitType] = VisitType ),
            [Form_Instance_ID]
        )

        
    RETURN
IF(Med=BLANK(), NoSelectedMed, CountMedAgeGroup)
&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 04 Jul 2023 09:46:40 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Refer-to-calculated-table/m-p/3314123#M123953</guid>
      <dc:creator>Marieke2</dc:creator>
      <dc:date>2023-07-04T09:46:40Z</dc:date>
    </item>
    <item>
      <title>Re: Refer to calculated table</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Refer-to-calculated-table/m-p/3315138#M124027</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="javascript:void(0)" data-lia-user-mentions="" data-lia-user-uid="382962" data-lia-user-login="Marieke2" class="lia-mention lia-mention-user"&gt;Marieke2&lt;/a&gt;&amp;nbsp;,&lt;/P&gt;
&lt;P&gt;It's glad to hear that your problem has been resolved. And thanks for sharing your solution here. Could you please mark your post&amp;nbsp;as&amp;nbsp;&lt;STRONG&gt;Answered&lt;/STRONG&gt;?&amp;nbsp;It will help the others in the community find the solution &lt;STRONG&gt;easily&lt;/STRONG&gt; if they face the same problem as yours. &amp;nbsp;Thank you.&lt;/P&gt;
&lt;P&gt;Best Regards&lt;/P&gt;</description>
      <pubDate>Wed, 05 Jul 2023 01:13:57 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Refer-to-calculated-table/m-p/3315138#M124027</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2023-07-05T01:13:57Z</dc:date>
    </item>
  </channel>
</rss>

