<?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 Compare values from DAX measures by a slicer selection in DAX Commands and Tips</title>
    <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Compare-values-from-DAX-measures-by-a-slicer-selection/m-p/915261#M8864</link>
    <description>&lt;P&gt;Hi DAX masters,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I need to achieve a little bit complicated task for me. Here is a scenario:&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;Slicer with Date dimension (year_month field)&lt;/LI&gt;&lt;LI&gt;When only one date is selected, calculate the difference of a measure for the selected month with the previous month&lt;/LI&gt;&lt;LI&gt;When more dates are selected, calculate the difference of a measure for the newest of selected months with the oldest of selected months&lt;P&gt;Now my solution which doesn't work:&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;Measure to be compared:&amp;nbsp;&lt;UL&gt;&lt;LI&gt;M_volume:=Sum(Fact_Volume[Volume])&lt;/LI&gt;&lt;/UL&gt;&lt;/LI&gt;&lt;LI&gt;Measure for calculation:&lt;UL&gt;&lt;LI&gt;M7_DeployedVolumeChanges:=CALCULATE([M2_VolumeCurrentMonth]-[M3_VolumePreviousMonth])&lt;/LI&gt;&lt;/UL&gt;&lt;/LI&gt;&lt;LI&gt;Two measures to calculate the needed values:&lt;UL&gt;&lt;LI&gt;M2_VolumeCurrentMonth:=&lt;BR /&gt;VAR CurrentYearMonth = MAX(Dim_Charge_date[Charge_date_SK])&lt;BR /&gt;VAR CurrentYear = VALUE(MID(FORMAT(CurrentYearMonth,"General Number"),1,4))&lt;BR /&gt;VAR CurrentMonth = VALUE(MID(FORMAT(CurrentYearMonth,"General Number"),5,2))&lt;BR /&gt;RETURN&lt;BR /&gt;CALCULATE(Fact_Volume[M_volume],FILTER(ALL(Dim_Charge_date),[YearNumber] = CurrentYear &amp;amp;&amp;amp; [MonthNumber] = CurrentMonth))&lt;/LI&gt;&lt;LI&gt;M3_VolumePreviousMonth:=&lt;BR /&gt;VAR CurrentYearMonth = MAX(Dim_Charge_date[Charge_date_SK])&lt;BR /&gt;VAR CurrentYear = VALUE(MID(FORMAT(CurrentYearMonth,"General Number"),1,4))&lt;BR /&gt;VAR CurrentMonth = VALUE(MID(FORMAT(CurrentYearMonth,"General Number"),5,2))&lt;BR /&gt;VAR PrevioseYearMonth = MIN(Dim_Charge_date[Charge_date_SK])&lt;BR /&gt;VAR PrevioseMonth = VALUE(MID(FORMAT(PrevioseYearMonth,"General Number"),5,2))&lt;BR /&gt;VAR PreviouseYear = VALUE(MID(FORMAT(PrevioseYearMonth,"General Number"),1,4))&lt;BR /&gt;RETURN&lt;BR /&gt;IF(CurrentYear = PreviouseYear &amp;amp;&amp;amp; CurrentMonth = PrevioseMonth,&lt;BR /&gt;IF(CurrentMonth=1,&lt;BR /&gt;CALCULATE(Fact_Volume[M_volume],FILTER(ALL( Dim_Charge_date),[YearNumber]= CurrentYear - 1 &amp;amp;&amp;amp; [MonthNumber] = CurrentMonth + 11)),&lt;BR /&gt;CALCULATE(Fact_Volume[M_volume],FILTER(ALL( Dim_Charge_date),[YearNumber]= CurrentYear &amp;amp;&amp;amp; [MonthNumber] = CurrentMonth - 1)))&lt;BR /&gt;,&lt;BR /&gt;CALCULATE(Fact_Volume[M_volume],FILTER(ALL(Dim_Charge_date),[YearNumber] =PreviouseYear &amp;amp;&amp;amp; [MonthNumber] = PrevioseMonth)))&lt;/LI&gt;&lt;/UL&gt;&lt;/LI&gt;&lt;LI&gt;Dim_Charge_date is a Date dimension and one attribute from this table is in the slicer.&lt;/LI&gt;&lt;LI&gt;Charge_date_SK is the only one numerical attribute which could be used for comparison and has this format: YYYYMMDD&lt;/LI&gt;&lt;/UL&gt;&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;I hope that the scenario is understandable. Now I have an issue:&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;There is something wrong with M3_VolumePreviousMonth. I receive an error: Cannot convert value '' of type Text to type Number and don't know why.&lt;/LI&gt;&lt;LI&gt;Could you please check if the concept is correct and if not tell me what's wrong with it?&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you very much in advance.&lt;/P&gt;&lt;P&gt;Zdenek&lt;/P&gt;</description>
    <pubDate>Wed, 29 Jan 2020 15:15:16 GMT</pubDate>
    <dc:creator>soldous</dc:creator>
    <dc:date>2020-01-29T15:15:16Z</dc:date>
    <item>
      <title>Compare values from DAX measures by a slicer selection</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Compare-values-from-DAX-measures-by-a-slicer-selection/m-p/915261#M8864</link>
      <description>&lt;P&gt;Hi DAX masters,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I need to achieve a little bit complicated task for me. Here is a scenario:&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;Slicer with Date dimension (year_month field)&lt;/LI&gt;&lt;LI&gt;When only one date is selected, calculate the difference of a measure for the selected month with the previous month&lt;/LI&gt;&lt;LI&gt;When more dates are selected, calculate the difference of a measure for the newest of selected months with the oldest of selected months&lt;P&gt;Now my solution which doesn't work:&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;Measure to be compared:&amp;nbsp;&lt;UL&gt;&lt;LI&gt;M_volume:=Sum(Fact_Volume[Volume])&lt;/LI&gt;&lt;/UL&gt;&lt;/LI&gt;&lt;LI&gt;Measure for calculation:&lt;UL&gt;&lt;LI&gt;M7_DeployedVolumeChanges:=CALCULATE([M2_VolumeCurrentMonth]-[M3_VolumePreviousMonth])&lt;/LI&gt;&lt;/UL&gt;&lt;/LI&gt;&lt;LI&gt;Two measures to calculate the needed values:&lt;UL&gt;&lt;LI&gt;M2_VolumeCurrentMonth:=&lt;BR /&gt;VAR CurrentYearMonth = MAX(Dim_Charge_date[Charge_date_SK])&lt;BR /&gt;VAR CurrentYear = VALUE(MID(FORMAT(CurrentYearMonth,"General Number"),1,4))&lt;BR /&gt;VAR CurrentMonth = VALUE(MID(FORMAT(CurrentYearMonth,"General Number"),5,2))&lt;BR /&gt;RETURN&lt;BR /&gt;CALCULATE(Fact_Volume[M_volume],FILTER(ALL(Dim_Charge_date),[YearNumber] = CurrentYear &amp;amp;&amp;amp; [MonthNumber] = CurrentMonth))&lt;/LI&gt;&lt;LI&gt;M3_VolumePreviousMonth:=&lt;BR /&gt;VAR CurrentYearMonth = MAX(Dim_Charge_date[Charge_date_SK])&lt;BR /&gt;VAR CurrentYear = VALUE(MID(FORMAT(CurrentYearMonth,"General Number"),1,4))&lt;BR /&gt;VAR CurrentMonth = VALUE(MID(FORMAT(CurrentYearMonth,"General Number"),5,2))&lt;BR /&gt;VAR PrevioseYearMonth = MIN(Dim_Charge_date[Charge_date_SK])&lt;BR /&gt;VAR PrevioseMonth = VALUE(MID(FORMAT(PrevioseYearMonth,"General Number"),5,2))&lt;BR /&gt;VAR PreviouseYear = VALUE(MID(FORMAT(PrevioseYearMonth,"General Number"),1,4))&lt;BR /&gt;RETURN&lt;BR /&gt;IF(CurrentYear = PreviouseYear &amp;amp;&amp;amp; CurrentMonth = PrevioseMonth,&lt;BR /&gt;IF(CurrentMonth=1,&lt;BR /&gt;CALCULATE(Fact_Volume[M_volume],FILTER(ALL( Dim_Charge_date),[YearNumber]= CurrentYear - 1 &amp;amp;&amp;amp; [MonthNumber] = CurrentMonth + 11)),&lt;BR /&gt;CALCULATE(Fact_Volume[M_volume],FILTER(ALL( Dim_Charge_date),[YearNumber]= CurrentYear &amp;amp;&amp;amp; [MonthNumber] = CurrentMonth - 1)))&lt;BR /&gt;,&lt;BR /&gt;CALCULATE(Fact_Volume[M_volume],FILTER(ALL(Dim_Charge_date),[YearNumber] =PreviouseYear &amp;amp;&amp;amp; [MonthNumber] = PrevioseMonth)))&lt;/LI&gt;&lt;/UL&gt;&lt;/LI&gt;&lt;LI&gt;Dim_Charge_date is a Date dimension and one attribute from this table is in the slicer.&lt;/LI&gt;&lt;LI&gt;Charge_date_SK is the only one numerical attribute which could be used for comparison and has this format: YYYYMMDD&lt;/LI&gt;&lt;/UL&gt;&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;I hope that the scenario is understandable. Now I have an issue:&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;There is something wrong with M3_VolumePreviousMonth. I receive an error: Cannot convert value '' of type Text to type Number and don't know why.&lt;/LI&gt;&lt;LI&gt;Could you please check if the concept is correct and if not tell me what's wrong with it?&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you very much in advance.&lt;/P&gt;&lt;P&gt;Zdenek&lt;/P&gt;</description>
      <pubDate>Wed, 29 Jan 2020 15:15:16 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Compare-values-from-DAX-measures-by-a-slicer-selection/m-p/915261#M8864</guid>
      <dc:creator>soldous</dc:creator>
      <dc:date>2020-01-29T15:15:16Z</dc:date>
    </item>
    <item>
      <title>Re: Compare values from DAX measures by a slicer selection</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Compare-values-from-DAX-measures-by-a-slicer-selection/m-p/915290#M8867</link>
      <description>&lt;P&gt;Ok, so the error was on my side in the Date dimension.&amp;nbsp;&lt;/P&gt;&lt;P&gt;There was Charge_date_SK with value -1 which caused the error.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I leave the solution here for inspiration.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 29 Jan 2020 15:36:07 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Compare-values-from-DAX-measures-by-a-slicer-selection/m-p/915290#M8867</guid>
      <dc:creator>soldous</dc:creator>
      <dc:date>2020-01-29T15:36:07Z</dc:date>
    </item>
  </channel>
</rss>

