<?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 Return the Index of today in DAX Commands and Tips</title>
    <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Return-the-Index-of-today/m-p/3805336#M148788</link>
    <description>&lt;P&gt;Dear all&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;First, sorry for my poor English level.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;A quick explanation of my problem:&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have a dataset based on a date table (calendar) but for all my visuals/calculations I use another table named 'calendar Fiscal' (both are linked on the date field).&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have a problem when I try to calculate the revenues for the last 12 months for example (except the current one).&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;If I use the following code:&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;Last 12 Months = 

VAR DateStart =  EDATE ( EOMONTH ( TODAY (), -1 ), -12 ) + 1
VAR DateEnd = TODAY ()

return
CALCULATE(
	switch(
        TRUE(),
        SELECTEDVALUE(_Metric[_Metric Commande])=0,SUM('CDD - Invoiced Sales'[Quantity in Base UOM]),
    	SELECTEDVALUE(_Metric[_Metric Commande])=1,SUM('CDD - Invoiced Sales'[Net Sales USD])	    
	),
	DATESBETWEEN('Calendar Fiscal'[TFS Date],DateStart,DateEnd)
)&lt;/LI-CODE&gt;&lt;P&gt;Both Var are based on my calendar table and not my calendar Fiscal table... so I have a difference between the value calculated and the real one (because my Fiscal Month aren't fiting the normal one):&lt;/P&gt;&lt;P&gt;ex: Fiscal March Month begins on 3rd March and ends on 30rd March.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;To bypass this problem I have created an Index on my fiscal calendar based on the column YYYY-MM and I would like to use it in my calculation.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I tried this code:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;Last 12 Months test = 

Var MaxIndex = MAX('Calendar Fiscal'[Index])
Var MinIndex = MaxIndex - 12

Var Result =
CALCULATE(
	switch(
        TRUE(),
        SELECTEDVALUE(_Metric[_Metric Commande])=0,SUM('CDD - Invoiced Sales'[Quantity in Base UOM]),
    	SELECTEDVALUE(_Metric[_Metric Commande])=1,SUM('CDD - Invoiced Sales'[Net Sales USD])	    
	),
	FILTER(ALL('Calendar Fiscal'),
    'Calendar Fiscal'[Index] &amp;lt;= MaxIndex &amp;amp;&amp;amp;
    'Calendar Fiscal'[Index] &amp;gt; MinIndex)
)
return Result&lt;/LI-CODE&gt;&lt;P&gt;but it's not good for the variable MaxIndex....&lt;/P&gt;&lt;P&gt;I would like to return the 'calendar Fiscal' [Index ] of previous month of the current day (today) but I don't know how to do that&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;ps: I'm not an expert of PowerBI &lt;span class="lia-unicode-emoji" title=":winking_face:"&gt;😉&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;many thanks in advance&lt;/P&gt;</description>
    <pubDate>Tue, 02 Apr 2024 15:12:00 GMT</pubDate>
    <dc:creator>Kev59</dc:creator>
    <dc:date>2024-04-02T15:12:00Z</dc:date>
    <item>
      <title>Return the Index of today</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Return-the-Index-of-today/m-p/3805336#M148788</link>
      <description>&lt;P&gt;Dear all&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;First, sorry for my poor English level.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;A quick explanation of my problem:&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have a dataset based on a date table (calendar) but for all my visuals/calculations I use another table named 'calendar Fiscal' (both are linked on the date field).&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have a problem when I try to calculate the revenues for the last 12 months for example (except the current one).&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;If I use the following code:&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;Last 12 Months = 

VAR DateStart =  EDATE ( EOMONTH ( TODAY (), -1 ), -12 ) + 1
VAR DateEnd = TODAY ()

return
CALCULATE(
	switch(
        TRUE(),
        SELECTEDVALUE(_Metric[_Metric Commande])=0,SUM('CDD - Invoiced Sales'[Quantity in Base UOM]),
    	SELECTEDVALUE(_Metric[_Metric Commande])=1,SUM('CDD - Invoiced Sales'[Net Sales USD])	    
	),
	DATESBETWEEN('Calendar Fiscal'[TFS Date],DateStart,DateEnd)
)&lt;/LI-CODE&gt;&lt;P&gt;Both Var are based on my calendar table and not my calendar Fiscal table... so I have a difference between the value calculated and the real one (because my Fiscal Month aren't fiting the normal one):&lt;/P&gt;&lt;P&gt;ex: Fiscal March Month begins on 3rd March and ends on 30rd March.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;To bypass this problem I have created an Index on my fiscal calendar based on the column YYYY-MM and I would like to use it in my calculation.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I tried this code:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;Last 12 Months test = 

Var MaxIndex = MAX('Calendar Fiscal'[Index])
Var MinIndex = MaxIndex - 12

Var Result =
CALCULATE(
	switch(
        TRUE(),
        SELECTEDVALUE(_Metric[_Metric Commande])=0,SUM('CDD - Invoiced Sales'[Quantity in Base UOM]),
    	SELECTEDVALUE(_Metric[_Metric Commande])=1,SUM('CDD - Invoiced Sales'[Net Sales USD])	    
	),
	FILTER(ALL('Calendar Fiscal'),
    'Calendar Fiscal'[Index] &amp;lt;= MaxIndex &amp;amp;&amp;amp;
    'Calendar Fiscal'[Index] &amp;gt; MinIndex)
)
return Result&lt;/LI-CODE&gt;&lt;P&gt;but it's not good for the variable MaxIndex....&lt;/P&gt;&lt;P&gt;I would like to return the 'calendar Fiscal' [Index ] of previous month of the current day (today) but I don't know how to do that&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;ps: I'm not an expert of PowerBI &lt;span class="lia-unicode-emoji" title=":winking_face:"&gt;😉&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;many thanks in advance&lt;/P&gt;</description>
      <pubDate>Tue, 02 Apr 2024 15:12:00 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Return-the-Index-of-today/m-p/3805336#M148788</guid>
      <dc:creator>Kev59</dc:creator>
      <dc:date>2024-04-02T15:12:00Z</dc:date>
    </item>
    <item>
      <title>Re: Return the Index of today</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Return-the-Index-of-today/m-p/3806497#M148839</link>
      <description>&lt;P&gt;Hi,&amp;nbsp;&lt;a href="javascript:void(0)" data-lia-user-mentions="" data-lia-user-uid="716620" data-lia-user-login="Kev59" class="lia-mention lia-mention-user"&gt;Kev59&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Depending on your description, you can try the following DAX expressions:&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;Last 12 Months Fiscal =
VAR CurrentDate =
    TODAY ()
VAR FiscalTodayIndex =
    CALCULATE (
        MAX ( 'Calendar Fiscal'[Index] ),
        FILTER ( 'Calendar Fiscal', 'Calendar Fiscal'[Date] = CurrentDate )
    )
VAR StartIndex = FiscalTodayIndex - 12
VAR EndIndex = FiscalTodayIndex - 1
RETURN
    CALCULATE (
        SWITCH (
            TRUE (),
            SELECTEDVALUE ( _Metric[_Metric Commande] ) = 0, SUM ( 'CDD - Invoiced Sales'[Quantity in Base UOM] ),
            SELECTEDVALUE ( _Metric[_Metric Commande] ) = 1, SUM ( 'CDD - Invoiced Sales'[Net Sales USD] )
        ),
        FILTER (
            ALL ( 'Calendar Fiscal' ),
            'Calendar Fiscal'[Index] &amp;gt; StartIndex
                &amp;amp;&amp;amp; 'Calendar Fiscal'[Index] &amp;lt;= EndIndex
        )
    )
&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;A href="https://nam06.safelinks.protection.outlook.com/?url=https%3A%2F%2Fcommunity.powerbi.com%2Ft5%2FCommunity-Blog%2FHow-to-Get-Your-Question-Answered-Quickly%2Fba-p%2F38490&amp;amp;data=05%7C02%7Cv-jianpengli%40microsoft.com%7Cd9552f18a0c94a7564f308dc188bf35e%7C72f988bf86f141af91ab2d7cd011db47%7C1%7C0%7C638412236574903368%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&amp;amp;sdata=3jxUE%2BTNC8dS4DIhPphEB3NA%2BK94pwURGHu%2BXC4eezw%3D&amp;amp;reserved=0" target="_blank"&gt;How to Get Your Question Answered Quickly&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;If it does not help, please provide more details with your desired output and pbix file without privacy information (or some sample data) .&lt;/P&gt;
&lt;P&gt;Best Regards&lt;/P&gt;
&lt;P&gt;Jianpeng Li&lt;/P&gt;
&lt;P&gt;If this post&amp;nbsp;&lt;STRONG&gt;&lt;EM&gt;helps&lt;/EM&gt;&lt;/STRONG&gt;, then please consider&amp;nbsp;&lt;STRONG&gt;&lt;EM&gt;Accept it as the solution&lt;/EM&gt;&lt;/STRONG&gt;&amp;nbsp;to help the other members find it more quickly.&lt;/P&gt;</description>
      <pubDate>Wed, 03 Apr 2024 04:35:52 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Return-the-Index-of-today/m-p/3806497#M148839</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2024-04-03T04:35:52Z</dc:date>
    </item>
  </channel>
</rss>

