<?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: Custom Function to lookup Date from another table with filter in Power Query</title>
    <link>https://community.fabric.microsoft.com/t5/Power-Query/Custom-Function-to-lookup-Date-from-another-table-with-filter/m-p/2026985#M59636</link>
    <description>&lt;P&gt;Your code is DAX, not Power Query.&amp;nbsp; Install DAX Studio and learn how to use it for query optimization. As a starter you can simplify your query&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;Last Inspection = calculate(max(bi_vw_InspectionCompleted[Inspection Completed]),bi_vw_InspectionCompleted[Inspection Completed]&amp;lt;bi_vw_wr_AssetIncidentReport[Date_Occured])&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The condition&lt;/P&gt;
&lt;P&gt;bi_vw_AssetInventory[AssetID]=bi_vw_wr_AssetIncidentReport[AssetID]&lt;/P&gt;
&lt;P&gt;should be covered by the data model.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Thu, 19 Aug 2021 23:08:27 GMT</pubDate>
    <dc:creator>lbendlin</dc:creator>
    <dc:date>2021-08-19T23:08:27Z</dc:date>
    <item>
      <title>Custom Function to lookup Date from another table with filter</title>
      <link>https://community.fabric.microsoft.com/t5/Power-Query/Custom-Function-to-lookup-Date-from-another-table-with-filter/m-p/2026055#M59611</link>
      <description>&lt;P&gt;Good afternoon,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have the following DAX formula which I have been using to find the date a vehicle was last inspected:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;DIV&gt;&lt;DIV&gt;&lt;STRONG&gt;Last Inspection = calculate(max(bi_vw_InspectionCompleted[Inspection Completed]),filter(bi_vw_InspectionCompleted,bi_vw_InspectionCompleted[Inspection Completed]&amp;lt;bi_vw_wr_AssetIncidentReport[Date_Occured]),filter(bi_vw_AssetInventory,bi_vw_AssetInventory[AssetID]=bi_vw_wr_AssetIncidentReport[AssetID]))&lt;/STRONG&gt;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;My problem is that whilst this works with a small subset of my data, I run into memory resouce issues when more data is loaded and the report is published to the Service. I have little to no experience with Power (M) Query.&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;Is there a way in which I could create a Custom function to perform this task?&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;Any assistance is appreciated.&lt;/SPAN&gt;&lt;/DIV&gt;&lt;/DIV&gt;</description>
      <pubDate>Thu, 19 Aug 2021 12:23:25 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Power-Query/Custom-Function-to-lookup-Date-from-another-table-with-filter/m-p/2026055#M59611</guid>
      <dc:creator>msommerf</dc:creator>
      <dc:date>2021-08-19T12:23:25Z</dc:date>
    </item>
    <item>
      <title>Re: Custom Function to lookup Date from another table with filter</title>
      <link>https://community.fabric.microsoft.com/t5/Power-Query/Custom-Function-to-lookup-Date-from-another-table-with-filter/m-p/2026985#M59636</link>
      <description>&lt;P&gt;Your code is DAX, not Power Query.&amp;nbsp; Install DAX Studio and learn how to use it for query optimization. As a starter you can simplify your query&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;Last Inspection = calculate(max(bi_vw_InspectionCompleted[Inspection Completed]),bi_vw_InspectionCompleted[Inspection Completed]&amp;lt;bi_vw_wr_AssetIncidentReport[Date_Occured])&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The condition&lt;/P&gt;
&lt;P&gt;bi_vw_AssetInventory[AssetID]=bi_vw_wr_AssetIncidentReport[AssetID]&lt;/P&gt;
&lt;P&gt;should be covered by the data model.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 19 Aug 2021 23:08:27 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Power-Query/Custom-Function-to-lookup-Date-from-another-table-with-filter/m-p/2026985#M59636</guid>
      <dc:creator>lbendlin</dc:creator>
      <dc:date>2021-08-19T23:08:27Z</dc:date>
    </item>
    <item>
      <title>Re: Custom Function to lookup Date from another table with filter</title>
      <link>https://community.fabric.microsoft.com/t5/Power-Query/Custom-Function-to-lookup-Date-from-another-table-with-filter/m-p/2027757#M59668</link>
      <description>&lt;P&gt;Hi, Thank you for your response,&lt;/P&gt;&lt;P&gt;I will look to get DAX Studio installed as suggested. Lots to learn!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;My data model consists of 3 tables:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;bi_vw_AssetInventory - This contains a unique list of assets.&lt;/P&gt;&lt;P&gt;bi_vw_InspectionCompleted - This contains a list of multiple Inspections for each asset.&lt;/P&gt;&lt;P&gt;bi_vw_AssetIncidentReport - This contains a list of multiple defects found for each asset.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The 3 table are connected on the AssetID field.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;If I use the DAX statement you have provided, I get an error :&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;img /&gt;&lt;/P&gt;&lt;P&gt;Whilst I realise the code I posted was DAX, I was wondering how the same result could be reached using Power Query.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 20 Aug 2021 07:57:52 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Power-Query/Custom-Function-to-lookup-Date-from-another-table-with-filter/m-p/2027757#M59668</guid>
      <dc:creator>msommerf</dc:creator>
      <dc:date>2021-08-20T07:57:52Z</dc:date>
    </item>
    <item>
      <title>Re: Custom Function to lookup Date from another table with filter</title>
      <link>https://community.fabric.microsoft.com/t5/Power-Query/Custom-Function-to-lookup-Date-from-another-table-with-filter/m-p/2028205#M59688</link>
      <description>&lt;P&gt;Your error message indicates that you use an older version of Power BI Desktop. Please update.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Power Query is notoriously bad at joining tables. Use the data model for that - that's its job.&lt;/P&gt;</description>
      <pubDate>Fri, 20 Aug 2021 13:42:06 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Power-Query/Custom-Function-to-lookup-Date-from-another-table-with-filter/m-p/2028205#M59688</guid>
      <dc:creator>lbendlin</dc:creator>
      <dc:date>2021-08-20T13:42:06Z</dc:date>
    </item>
    <item>
      <title>Re: Custom Function to lookup Date from another table with filter</title>
      <link>https://community.fabric.microsoft.com/t5/Power-Query/Custom-Function-to-lookup-Date-from-another-table-with-filter/m-p/2034368#M59868</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="javascript:void(0)" data-lia-user-mentions="" data-lia-user-uid="126730" data-lia-user-login="msommerf" class="lia-mention lia-mention-user"&gt;msommerf&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Since all tables have the&amp;nbsp;&lt;SPAN&gt;AssetID field, you could try below code to create a column.&lt;/SPAN&gt;&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;Last Inspection 2 = 
MAXX (
    FILTER (
        bi_vw_InspectionCompleted,
        bi_vw_InspectionCompleted[AssetID] = bi_vw_wr_AssetIncidentReport[AssetID]
            &amp;amp;&amp;amp; bi_vw_InspectionCompleted[Inspection Completed] &amp;lt; bi_vw_wr_AssetIncidentReport[Date_Occured]
    ),
    bi_vw_InspectionCompleted[Inspection Completed]
)&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you want to try Power Query, you could add below steps to&amp;nbsp;&lt;SPAN&gt;bi_vw_AssetIncidentReport query. I'm not sure whether this would run into memory resource issues when large data is loaded, you may have a try. I attach the pbix for your reference.&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;    #"Merged Queries" = Table.NestedJoin(#"Changed Type", {"AssetID"}, bi_vw_InspectionCompleted, {"AssetID"}, "bi_vw_InspectionCompleted", JoinKind.LeftOuter),
    #"Added Custom" = Table.AddColumn(#"Merged Queries", "Custom", each List.Max(let occurredDate = [Date_Occured] in
List.Select([bi_vw_InspectionCompleted][Inspection Completed], each _ &amp;lt; occurredDate))),
    #"Removed Columns" = Table.RemoveColumns(#"Added Custom",{"bi_vw_InspectionCompleted"})&lt;/LI-CODE&gt;
&lt;P&gt;&lt;img /&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Regards, &lt;BR /&gt;Community Support Team _ Jing&lt;BR /&gt;If this post helps, please Accept it as the solution to help other members find it.&lt;/P&gt;</description>
      <pubDate>Tue, 24 Aug 2021 08:26:35 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Power-Query/Custom-Function-to-lookup-Date-from-another-table-with-filter/m-p/2034368#M59868</guid>
      <dc:creator>v-jingzhang</dc:creator>
      <dc:date>2021-08-24T08:26:35Z</dc:date>
    </item>
    <item>
      <title>Re: Custom Function to lookup Date from another table with filter</title>
      <link>https://community.fabric.microsoft.com/t5/Power-Query/Custom-Function-to-lookup-Date-from-another-table-with-filter/m-p/2037987#M59952</link>
      <description>&lt;P&gt;A sincere thank you for going to the trouble of finding a solution by mocking up tables etc.&lt;/P&gt;&lt;P&gt;The DAX solution shown above has solved my issue.&lt;/P&gt;&lt;P&gt;I can now do an incremental refresh with a years worth of data.&lt;/P&gt;&lt;P&gt;&lt;span class="lia-unicode-emoji" title=":thumbs_up:"&gt;👍&lt;/span&gt;&lt;/P&gt;&lt;P&gt;Thank you so much.&lt;/P&gt;&lt;P&gt;Regards&lt;/P&gt;&lt;P&gt;Mark.&lt;/P&gt;</description>
      <pubDate>Wed, 25 Aug 2021 14:37:57 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Power-Query/Custom-Function-to-lookup-Date-from-another-table-with-filter/m-p/2037987#M59952</guid>
      <dc:creator>msommerf</dc:creator>
      <dc:date>2021-08-25T14:37:57Z</dc:date>
    </item>
    <item>
      <title>Re: Custom Function to lookup Date from another table with filter</title>
      <link>https://community.fabric.microsoft.com/t5/Power-Query/Custom-Function-to-lookup-Date-from-another-table-with-filter/m-p/2039032#M59977</link>
      <description>&lt;P&gt;Glad it helps! You are welcome!&amp;nbsp;&lt;span class="lia-unicode-emoji" title=":smiling_face_with_smiling_eyes:"&gt;😊&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 26 Aug 2021 01:33:41 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Power-Query/Custom-Function-to-lookup-Date-from-another-table-with-filter/m-p/2039032#M59977</guid>
      <dc:creator>v-jingzhang</dc:creator>
      <dc:date>2021-08-26T01:33:41Z</dc:date>
    </item>
  </channel>
</rss>

