<?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: LASTNONBLANK issue in DAX Commands and Tips</title>
    <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/LASTNONBLANK-issue/m-p/3451637#M131503</link>
    <description>&lt;P&gt;&lt;a href="javascript:void(0)" data-lia-user-mentions="" data-lia-user-uid="555045" data-lia-user-login="some_bih" class="lia-mention lia-mention-user"&gt;some_bih&lt;/a&gt;&amp;nbsp; Thanks so much. I'll definitely work through that article. That might just be a better way than I'm doing at the moment.&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;Yes the dates was a typo &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;BR /&gt;&lt;BR /&gt;I'm still quite curious why LASTNONBLANK is not returning the correct value.&amp;nbsp;&lt;/P&gt;&lt;P&gt;For 2021 its working well up until 31 March 2021 and for 2022 its working well up until 30 September 2022.&amp;nbsp;&lt;BR /&gt;Its strange to see a formula performing as expected for a certain portion of the year, but not for the other portion of the year&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;</description>
    <pubDate>Thu, 28 Sep 2023 12:10:32 GMT</pubDate>
    <dc:creator>Drikus</dc:creator>
    <dc:date>2023-09-28T12:10:32Z</dc:date>
    <item>
      <title>LASTNONBLANK issue</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/LASTNONBLANK-issue/m-p/3450610#M131431</link>
      <description>&lt;P&gt;I have a listing of sales invoices which I need to translate the value to USD using the rate on the date of the invoice.&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have set up an FX table that automatically imports the FX rates from the European Central bank to create a table for FX rates.&amp;nbsp;&lt;/P&gt;&lt;P&gt;There are no exchange rates released for certain days (weekends, public holidays etc).&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;I have created a calculated column to calculate the date of the latest available date using LASTNONBLANK.&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have also created a column to see how many days are between my calculated FX date and the Invoice date.&amp;nbsp;&lt;/P&gt;&lt;P&gt;I would only expect to see between 0-4 days variance between the two, but I'm seeing large numbers.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;For 2021 its working well till it gets to March and is then stuck on 31 March 2021 till the end of the year.&amp;nbsp;&lt;/P&gt;&lt;P&gt;For 2022 its the same story it works well till the 30th of September and is then stuck on that date till the end of the year.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;img /&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;img /&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;What could I be doing wrong in my calculation for the Latest available date?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;U&gt;My issue can easily be recreated.&amp;nbsp;&lt;/U&gt;&lt;/P&gt;&lt;P&gt;I have 3 Tables&amp;nbsp;&lt;/P&gt;&lt;P&gt;d_Date which is my date table and marked as a date table.&amp;nbsp;&lt;BR /&gt;ECB_FXRate which is the exchange rates per the European Central bank. MCode code down below.&amp;nbsp;&lt;/P&gt;&lt;P&gt;Invoice listing (TEST DATE). Which I've just recreated as being each day in the year to test the formula&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Date table below (Calculated Table):&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;d_Date = 
ADDCOLUMNS (
CALENDAR(DATE(2021,01,01),Date(2023,12,01)),
    "DateKey", VALUE ( FORMAT ( [Date], "YYYYMMDD" ) ),
    "Year", YEAR ( [Date] ),
    "Quarter Number", INT ( FORMAT ( [Date], "q" ) ),
    "Quarter", "Q" &amp;amp; INT ( FORMAT ( [Date], "q" ) ),
    "Month Number", MONTH ( [Date] ),
    "Month", FORMAT ( [Date], "mmmm" ),
    "Week Day Number", WEEKDAY ( [Date] ),
    "Week Day", FORMAT ( [Date], "dddd" ),
    "Year Month Number", YEAR ( [Date] ) * 100 + MONTH ( [Date] ),
    "Year Month", FORMAT ( [Date], "mmmm" ) &amp;amp; " " &amp;amp; YEAR ( [Date] ),
    "Year Quarter Number", YEAR ( [Date] ) * 100 + INT ( FORMAT ( [Date], "q" ) ),
    "Year Quarter", "Q" &amp;amp; FORMAT ( [Date], "q" ) &amp;amp; "-" &amp;amp; YEAR ( [Date] ),
    "Day",DAY([Date]),
    "Month End",EOMONTH([Date],0)
)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;ECB_FXRates - MCode to create FX Rate Table:&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;let
  Source = Xml.Tables(
    Web.Contents(
      "https://www.ecb.europa.eu/stats/eurofxref/eurofxref-sdmx.xml?11c21b73004dd2d4795959d4cfff466b"
    )
  ), 
  Table1 = Source{1}[Table], 
  Table0 = Table1{0}[Table], 
  Table2 = Table0{1}[Table], 
  #"Changed Type" = Table.TransformColumnTypes(
    Table2, 
    {
      {"Attribute:FREQ", type text}, 
      {"Attribute:CURRENCY", type text}, 
      {"Attribute:CURRENCY_DENOM", type text}, 
      {"Attribute:EXR_TYPE", type text}, 
      {"Attribute:EXR_SUFFIX", type text}, 
      {"Attribute:TIME_FORMAT", type duration}, 
      {"Attribute:COLLECTION", type text}
    }
  ), 
  #"Removed Columns" = Table.RemoveColumns(
    #"Changed Type", 
    {
      "Attribute:FREQ", 
      "Attribute:CURRENCY_DENOM", 
      "Attribute:EXR_TYPE", 
      "Attribute:EXR_SUFFIX", 
      "Attribute:TIME_FORMAT", 
      "Attribute:COLLECTION"
    }
  ), 
  #"Filtered Rows" = Table.SelectRows(#"Removed Columns", each ([#"Attribute:CURRENCY"] = "CAD" or [#"Attribute:CURRENCY"] = "CNY" or [#"Attribute:CURRENCY"] = "GBP" or [#"Attribute:CURRENCY"] = "MXN" or [#"Attribute:CURRENCY"] = "TRY" or [#"Attribute:CURRENCY"] = "USD")),
    #"Expanded Obs" = Table.ExpandTableColumn(
    #"Filtered Rows", 
    "Obs", 
    {"Attribute:TIME_PERIOD", "Attribute:OBS_VALUE"}, 
    {"Attribute:TIME_PERIOD", "Attribute:OBS_VALUE"}
  ), 
  #"Changed Type1" = Table.TransformColumnTypes(
    #"Expanded Obs", 
    {{"Attribute:TIME_PERIOD", type date}, {"Attribute:OBS_VALUE", type number}}
  ), 
  #"Renamed Columns" = Table.RenameColumns(
    #"Changed Type1", 
    {
      {"Attribute:TIME_PERIOD", "Date"}, 
      {"Attribute:OBS_VALUE", "Value"}, 
      {"Attribute:CURRENCY", "Attribute"}
    }
  ),
    DateFilter = Table.SelectRows(#"Renamed Columns", each [Date] &amp;gt; #date(2020, 03, 01)),
    #"Add Euro" = Table.AddColumn(
    Table.AddColumn(
      Table.Distinct(Table.SelectColumns(DateFilter, "Date")), 
      "Attribute", 
      each "EUR", 
      type text
    ), 
    "Value", 
    each 1, 
    type number
  ), 
  #"Appended Query" = Table.Combine({#"Add Euro", DateFilter}), 
  #"Sorted Rows" = Table.Sort(#"Appended Query", {{"Date", Order.Ascending}}),
    AddUSDasBase = Table.AddColumn(#"Sorted Rows", "BaseRate", each "USD", type text),
    BufferedTable = Table.Buffer(AddUSDasBase),
    #"Merged Queries" = Table.NestedJoin(BufferedTable, {"Date", "BaseRate"}, AddUSDasBase, {"Date", "Attribute"}, "FX Table", JoinKind.LeftOuter),
    #"Expanded FX Rates" = Table.ExpandTableColumn(#"Merged Queries", "FX Table", {"Value"}, {"ToBaseRate"}),
    #"Added Custom" = Table.AddColumn(#"Expanded FX Rates", "USDRate", each Value.Divide([Value],[ToBaseRate]), type number),
    #"Removed Other Columns" = Table.SelectColumns(#"Added Custom",{"Date", "Attribute", "USDRate"}),
    FXTable = Table.RenameColumns(#"Removed Other Columns",{{"Attribute", "Currency"}})
in
    FXTable&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Invoice Listing (Calculated table):&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;TEST DATE =
ADDCOLUMNS (
    CALENDAR ( DATE ( 2021, 01, 01 ), DATE ( 2023, 12, 01 ) ),
    "Week Day Number", WEEKDAY ( [Date] ),
    "Week Day", FORMAT ( [Date], "dddd" )
)&lt;/LI-CODE&gt;&lt;P&gt;Calculated column formula in Invoice listing&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;FX_Date = 
VAR DDate = 'TEST DATE'[InvoiceDate]

VAR DateTable =
    FILTER ( 'd_Date', 'd_Date'[Date] &amp;lt;= DDate)

VAR Result =
CALCULATE (
VALUES('d_Date'[Date] ),
LASTNONBLANK ( DateTable, COUNTROWS ( RELATEDTABLE ( ECB_FXRates ) ) )
)

RETURN
Result&lt;/LI-CODE&gt;&lt;P&gt;&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;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 27 Sep 2023 21:59:04 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/LASTNONBLANK-issue/m-p/3450610#M131431</guid>
      <dc:creator>Drikus</dc:creator>
      <dc:date>2023-09-27T21:59:04Z</dc:date>
    </item>
    <item>
      <title>Re: LASTNONBLANK issue</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/LASTNONBLANK-issue/m-p/3451101#M131464</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="javascript:void(0)" data-lia-user-mentions="" data-lia-user-uid="410991" data-lia-user-login="Drikus" class="lia-mention lia-mention-user"&gt;Drikus&lt;/a&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Think about part - I guess typo? Put longer year as we are approaching to this deadline in less than 100 days:)&lt;/P&gt;&lt;P&gt;CALENDAR(DATE(2021,01,01),Date(2023,12,&lt;FONT color="#FF0000"&gt;01&lt;/FONT&gt;)),&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Great articles for your case, worth reading and implementations&lt;/P&gt;&lt;P&gt;&lt;A href="https://www.sqlbi.com/articles/currency-conversion-in-power-bi-reports/" target="_self"&gt;https://www.sqlbi.com/articles/currency-conversion-in-power-bi-reports/&lt;/A&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;or&lt;/P&gt;&lt;P&gt;&lt;A href="https://www.daxpatterns.com/currency-conversion/" target="_self"&gt;https://www.daxpatterns.com/currency-conversion/&lt;/A&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Hope this help, kudos appreciated.&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 28 Sep 2023 06:39:14 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/LASTNONBLANK-issue/m-p/3451101#M131464</guid>
      <dc:creator>some_bih</dc:creator>
      <dc:date>2023-09-28T06:39:14Z</dc:date>
    </item>
    <item>
      <title>Re: LASTNONBLANK issue</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/LASTNONBLANK-issue/m-p/3451637#M131503</link>
      <description>&lt;P&gt;&lt;a href="javascript:void(0)" data-lia-user-mentions="" data-lia-user-uid="555045" data-lia-user-login="some_bih" class="lia-mention lia-mention-user"&gt;some_bih&lt;/a&gt;&amp;nbsp; Thanks so much. I'll definitely work through that article. That might just be a better way than I'm doing at the moment.&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;Yes the dates was a typo &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;BR /&gt;&lt;BR /&gt;I'm still quite curious why LASTNONBLANK is not returning the correct value.&amp;nbsp;&lt;/P&gt;&lt;P&gt;For 2021 its working well up until 31 March 2021 and for 2022 its working well up until 30 September 2022.&amp;nbsp;&lt;BR /&gt;Its strange to see a formula performing as expected for a certain portion of the year, but not for the other portion of the year&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 28 Sep 2023 12:10:32 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/LASTNONBLANK-issue/m-p/3451637#M131503</guid>
      <dc:creator>Drikus</dc:creator>
      <dc:date>2023-09-28T12:10:32Z</dc:date>
    </item>
    <item>
      <title>Re: LASTNONBLANK issue</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/LASTNONBLANK-issue/m-p/3451663#M131508</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="javascript:void(0)" data-lia-user-mentions="" data-lia-user-uid="410991" data-lia-user-login="Drikus" class="lia-mention lia-mention-user"&gt;Drikus&lt;/a&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;LASTNONBLANK perform CONTEXT Transition so it is hard to understand what is wrong looking just simple measure definitions.&lt;/P&gt;</description>
      <pubDate>Thu, 28 Sep 2023 12:30:30 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/LASTNONBLANK-issue/m-p/3451663#M131508</guid>
      <dc:creator>some_bih</dc:creator>
      <dc:date>2023-09-28T12:30:30Z</dc:date>
    </item>
  </channel>
</rss>

