<?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: [German Stock Market] Evaluate a condition, return 0 or 1, sum it and calculate a percentage in DAX Commands and Tips</title>
    <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/German-Stock-Market-Evaluate-a-condition-return-0-or-1-sum-it/m-p/2813771#M89142</link>
    <description>&lt;P&gt;Try something like&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;Good days near bad days =
VAR RankingTable =
    SELECTCOLUMNS ( 'Table', 'Table'[Date], 'Table'[Top10 Best Worst] )
VAR Result =
    SUMX (
        RankingTable,
        VAR CurrentDate = 'Table'[Date]
        VAR CurrentRanking = 'Table'[Top10 Best Worst]
        RETURN
            IF (
                CurrentRanking = 1,
                VAR PrevBadDate =
                    CALCULATE (
                        MAXX ( RankingTable, 'Table'[Date] ),
                        'Table'[Date] &amp;lt; CurrentDate,
                        'Table'[Top10 Best Worst] = 2
                    )
                RETURN
                    IF ( DATEDIFF ( PrevBadDate, CurrentDate, DAY ) &amp;lt;= 14, 1 )
            )
    )
RETURN
    Result
&lt;/LI-CODE&gt;</description>
    <pubDate>Mon, 03 Oct 2022 11:36:08 GMT</pubDate>
    <dc:creator>johnt75</dc:creator>
    <dc:date>2022-10-03T11:36:08Z</dc:date>
    <item>
      <title>[German Stock Market] Evaluate a condition, return 0 or 1, sum it and calculate a percentage</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/German-Stock-Market-Evaluate-a-condition-return-0-or-1-sum-it/m-p/2813611#M89125</link>
      <description>&lt;P&gt;Hello dear Power BI Forum,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am creating a report about the German stock market index DAX40 (Top 40 German companies in terms of market capitalization) and came across the following statement, which i try to prove with the help of Dax.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;EM&gt;"60% of the best days in terms of yield return occur within the top 10 worst days of the year."&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;This basically means that a lot of good days in terms of return usually occur within two weeks of bad days.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I've already calculated the top10 best and top10 worst days of the year in terms of return, which looks like this:&lt;/P&gt;&lt;P&gt;&lt;img /&gt;&lt;/P&gt;&lt;P&gt;Plotting this onto a chart for a selected year of 2008 give the following result, which supports the statement, since the points are really close to eachother:&lt;/P&gt;&lt;P&gt;&lt;img /&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Now what i want to do with DAX (problem):&lt;/P&gt;&lt;P&gt;&lt;img /&gt;&lt;/P&gt;&lt;P&gt;1) Go to the first bad date of the year which is the 21st of January.&lt;/P&gt;&lt;P&gt;2) if a bad date follows, go to the next bad date&lt;/P&gt;&lt;P&gt;(in our case the 21st of January is followed by the 23rd of January, so we go to the 23rd of January)&lt;/P&gt;&lt;P&gt;3) Otherwise, if a bad date is followed by a good date, then calculate the datediff in Days, if it is within 14 days, return 1&lt;/P&gt;&lt;P&gt;4) calculate the sums of one's in the column&lt;/P&gt;&lt;P&gt;5) calculate the sums of the column divided by the number of good dates in the year&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;If I am not mistaken, the column should return a value of 9 (9*1).&lt;/P&gt;&lt;P&gt;So the statement would be true, because 90% of the best days happen within 14 days of the worst days.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;EM&gt;"60% of the best days in terms of yield return occur within the top 10 worst days of the year."&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I hope you get my point and understand my measure. Thank you for any help.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Kind regards&lt;/P&gt;&lt;P&gt;Hendrik&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;EDIT:&amp;nbsp;&lt;/P&gt;&lt;P&gt;You can use all the DAX you know, but I think we need sth like: Calculate, Calculatetable, Datediff, Divide and some Filter functions I am not aware of^^&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 03 Oct 2022 10:09:31 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/German-Stock-Market-Evaluate-a-condition-return-0-or-1-sum-it/m-p/2813611#M89125</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2022-10-03T10:09:31Z</dc:date>
    </item>
    <item>
      <title>Re: [German Stock Market] Evaluate a condition, return 0 or 1, sum it and calculate a percentage</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/German-Stock-Market-Evaluate-a-condition-return-0-or-1-sum-it/m-p/2813771#M89142</link>
      <description>&lt;P&gt;Try something like&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;Good days near bad days =
VAR RankingTable =
    SELECTCOLUMNS ( 'Table', 'Table'[Date], 'Table'[Top10 Best Worst] )
VAR Result =
    SUMX (
        RankingTable,
        VAR CurrentDate = 'Table'[Date]
        VAR CurrentRanking = 'Table'[Top10 Best Worst]
        RETURN
            IF (
                CurrentRanking = 1,
                VAR PrevBadDate =
                    CALCULATE (
                        MAXX ( RankingTable, 'Table'[Date] ),
                        'Table'[Date] &amp;lt; CurrentDate,
                        'Table'[Top10 Best Worst] = 2
                    )
                RETURN
                    IF ( DATEDIFF ( PrevBadDate, CurrentDate, DAY ) &amp;lt;= 14, 1 )
            )
    )
RETURN
    Result
&lt;/LI-CODE&gt;</description>
      <pubDate>Mon, 03 Oct 2022 11:36:08 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/German-Stock-Market-Evaluate-a-condition-return-0-or-1-sum-it/m-p/2813771#M89142</guid>
      <dc:creator>johnt75</dc:creator>
      <dc:date>2022-10-03T11:36:08Z</dc:date>
    </item>
  </channel>
</rss>

