<?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: Get selected values from Hierarchy respecting Hierarchy Level in DAX Commands and Tips</title>
    <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Get-selected-values-from-Hierarchy-respecting-Hierarchy-Level/m-p/3488263#M133500</link>
    <description>&lt;P&gt;Thanks again&amp;nbsp;&lt;a href="javascript:void(0)" data-lia-user-mentions="" data-lia-user-uid="39298" data-lia-user-login="AlexisOlson" class="lia-mention lia-mention-user"&gt;AlexisOlson&lt;/a&gt;.&amp;nbsp; I think that did it for me on the Date side.&amp;nbsp; I may continue to tweak the delimeter's to get it to a place that's visually what I want.&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;I am going to go back and try to modify the code for the Business Unit selection.&amp;nbsp; This one may be a little more complicated as there are 3 levels (BU 1, 2 and 3) versus 2 levels for the Date (Year, Month).&amp;nbsp;&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;Hopefully I can take what you've provided as a template and apply it further!&amp;nbsp; I'll reach out if I run into any issues.&amp;nbsp; Thanks again!&lt;/P&gt;&lt;P&gt;Zac&lt;/P&gt;</description>
    <pubDate>Fri, 20 Oct 2023 16:36:50 GMT</pubDate>
    <dc:creator>zoberender</dc:creator>
    <dc:date>2023-10-20T16:36:50Z</dc:date>
    <item>
      <title>Get selected values from Hierarchy respecting Hierarchy Level</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Get-selected-values-from-Hierarchy-respecting-Hierarchy-Level/m-p/3486419#M133408</link>
      <description>&lt;P&gt;Hi all,&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;I'm struggling on this issue.&amp;nbsp; I'd like to create a visual that shows which slicers are available.&amp;nbsp; Specifically, I have 2 slicers that are part of hierarchies that are being used.&amp;nbsp; The slicer on the date hierarchy uses 'Year Number' &amp;amp; 'Month Short Name' from my dim_Date table.&amp;nbsp; I also have a BU hierarchy that has BU Level 1, BU Level 2 and BU Level 3 from my dim_Account table.&amp;nbsp; What I'd really like to create is a visual that shows which slicers are applied.&amp;nbsp; I've been able to accomplish this for each of the individual fields, but they all get lumped together.&amp;nbsp; I know i need to combine these in some way to keep the levels in tact, but I can't for the life of me figure it out.&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;When there is no filter selected, I'd like to see something like:&lt;/P&gt;&lt;P&gt;ALL Years: All Months&lt;/P&gt;&lt;P&gt;If however the user selected Jan 2023, May &amp;amp; June 2022 and ALL of 2021&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;In Card form:&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;Dates Selected =&amp;nbsp;&lt;/P&gt;&lt;P&gt;2023: Jan&lt;/P&gt;&lt;P&gt;2022: May, June&lt;/P&gt;&lt;P&gt;2021: ALL Months&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;In table form:&lt;/STRONG&gt;&lt;/P&gt;&lt;TABLE border="1"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;Year&lt;/TD&gt;&lt;TD&gt;Month&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;2023&lt;/TD&gt;&lt;TD&gt;Jan&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;2022&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;May&lt;/P&gt;&lt;P&gt;June&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;2021&lt;/TD&gt;&lt;TD&gt;ALL Months&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'd also want to limit it to 3-4 results and return an etc (or something) if there are more selected.&amp;nbsp; And if there are no filters I don't want to show all of the years, I just want it to say ALL Years (or ALL Months), etc.&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Below is the code I have for the &lt;STRONG&gt;Selected Year&lt;/STRONG&gt;.&amp;nbsp; Same type of measure exists for Selected Month and the BU Levels as well.&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;Selected Year = 
VAR __DISTINCT_VALUES_COUNT = DISTINCTCOUNT('dim_Date'[Year Number])
VAR __MAX_VALUES_TO_SHOW = 3
RETURN
IF(ISFILTERED(dim_Date[Year Number]),
	IF(
		__DISTINCT_VALUES_COUNT &amp;gt; __MAX_VALUES_TO_SHOW,
		CONCATENATE(
			CONCATENATEX(
				TOPN(
					__MAX_VALUES_TO_SHOW,
					VALUES('dim_Date'[Year Number]),
					'dim_Date'[Year Number],
					ASC
				),
				'dim_Date'[Year Number],
				", ",
				'dim_Date'[Year Number],
				ASC
			),
			", etc."
		),
		CONCATENATEX(
			VALUES('dim_Date'[Year Number]),
			'dim_Date'[Year Number],
			", ",
			'dim_Date'[Year Number],
			ASC
		)
	), 
"ALL Years")&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;I also have a measure to combine Year and Month, that I hoped would have kept the correct year/month pairings together.&amp;nbsp; But alas it does not.&amp;nbsp;&amp;nbsp;With my existing measures, what I get is:&lt;BR /&gt;Selected Year &amp;amp; Month:&lt;/P&gt;&lt;P&gt;2021, 2022, 2023: ALL MONTHS&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;Selected Year &amp;amp; Month = [Selected Year] &amp;amp; ": " &amp;amp;[Selected Month]&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'm confident if I can get it working with the date, I can adapt it to work for the BU data as well.&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Hoping someone can help.&amp;nbsp; Thanks!&lt;BR /&gt;Zac&lt;/P&gt;</description>
      <pubDate>Thu, 19 Oct 2023 20:55:05 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Get-selected-values-from-Hierarchy-respecting-Hierarchy-Level/m-p/3486419#M133408</guid>
      <dc:creator>zoberender</dc:creator>
      <dc:date>2023-10-19T20:55:05Z</dc:date>
    </item>
    <item>
      <title>Re: Get selected values from Hierarchy respecting Hierarchy Level</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Get-selected-values-from-Hierarchy-respecting-Hierarchy-Level/m-p/3486511#M133411</link>
      <description>&lt;P&gt;I don't know if this is exactly what you need but it should get you closer and give you a starting place to tinker with:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="php"&gt;DateSelection = 
VAR __N = 3
VAR __FullSelection = SUMMARIZE ( Dates, Dates[Year], Dates[Month], Dates[MonthShort] )
VAR __Years = DISTINCT ( SELECTCOLUMNS ( __FullSelection, "Dates[Year]", Dates[Year] ) )
VAR __MonthsInYear = COUNTROWS ( ALL ( Dates[Month] ) )
VAR __TopNYears = TOPN ( __N, __Years, Dates[Year], DESC )
VAR __ExtraYears = COUNTROWS ( __Years ) - __N
VAR __Delim1 = UNICHAR(10) &amp;amp; "     "
VAR __Delim2 = UNICHAR(10)
VAR __ExtraString = IF ( __ExtraYears &amp;gt; 0, __Delim2 &amp;amp; " +" &amp;amp; __ExtraYears &amp;amp; " year(s)" )
RETURN
    CONCATENATEX (
        __TopNYears,
        VAR __CurrYear = Dates[Year]
        VAR __CurrSelection = FILTER ( __FullSelection, Dates[Year] = __CurrYear )
        VAR __MonthCount = COUNTROWS ( __CurrSelection )
        VAR __ExtraMonths = __MonthCount - __N
        VAR __TopNMonths = TOPN ( __N, __CurrSelection , Dates[Month], ASC )
        VAR __Concat =
            CONCATENATEX (
                __TopNMonths,
                Dates[MonthShort],
                __Delim1,
                Dates[Month], ASC
            )
        VAR __MonthText =
            SWITCH (
                TRUE(),
                __MonthCount = __MonthsInYear, "ALL",
                __MonthCount &amp;gt; __N, __Concat &amp;amp; __Delim1 &amp;amp; "+" &amp;amp; __ExtraMonths,
                __Concat
            )
        RETURN
            Dates[Year] &amp;amp; " " &amp;amp; __MonthText,
        __Delim2,
        Dates[Year], DESC
    ) &amp;amp; __ExtraString&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Note: I'm using my own date table. E.g., Date[Year] above corresponds to 'dim_Date'[Year Number] for you.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;BR /&gt;Sample outputs:&lt;/P&gt;
&lt;P&gt;&lt;img /&gt;&lt;/P&gt;
&lt;P&gt;&lt;img /&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 19 Oct 2023 22:44:33 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Get-selected-values-from-Hierarchy-respecting-Hierarchy-Level/m-p/3486511#M133411</guid>
      <dc:creator>AlexisOlson</dc:creator>
      <dc:date>2023-10-19T22:44:33Z</dc:date>
    </item>
    <item>
      <title>Re: Get selected values from Hierarchy respecting Hierarchy Level</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Get-selected-values-from-Hierarchy-respecting-Hierarchy-Level/m-p/3488161#M133497</link>
      <description>&lt;P&gt;Thanks &lt;a href="javascript:void(0)" data-lia-user-mentions="" data-lia-user-uid="39298" data-lia-user-login="AlexisOlson" class="lia-mention lia-mention-user"&gt;AlexisOlson&lt;/a&gt;&amp;nbsp;!&amp;nbsp; This gets me really close.&amp;nbsp; I've been trying to tweak a few things this morning.&amp;nbsp;&lt;/P&gt;&lt;P&gt;Added:&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;IF statement to the __ExtraString.&amp;nbsp; If there were only 2 year selected it would give a "+ - 1 year(s)" at the end.&amp;nbsp;&amp;nbsp;&lt;/LI&gt;&lt;LI&gt;IF( ISFILTERED statement to the RETURN string as I just wanted it to say "ALL Dates" if no filters are applied.&amp;nbsp;&amp;nbsp;&lt;/LI&gt;&lt;LI&gt;Changed dim_Date[Month Short Name] to dim_Date[Month Number] in the CONCATENATEX to sort the months correctly.&amp;nbsp;&amp;nbsp;&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;I think there is one piece left that I just can't get solved.&amp;nbsp; I should have mentioned this in my original question, but overlooked it.&amp;nbsp; My date table runs from 1/1/19 - 8/31/23.&amp;nbsp; What I can't solve is for the current year/month combination.&amp;nbsp; The measure you provided works as expected for 2022 and prior, but for 2023 there are only 8 months in the date table for the year.&amp;nbsp; For 2023, if I select the entire year (8 months), I would like to get back "ALL".&amp;nbsp; What I get back is 2023 Jan, Feb, Mar +5.&amp;nbsp; I know it has to do with the __MonthsInYear and __MonthCount, but haven't been able to get a solution figured out this morning.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;With all 8 months of 2023 selected, I expected to see "ALL" for 2023.&amp;nbsp; &amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;img /&gt;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;Date Selection = 
VAR __N = 3
VAR __FullSelection = SUMMARIZE ( dim_Date, dim_Date[Year Number], dim_Date[Month Name], dim_Date[Month Short Name], dim_Date[Month Number] ) 
VAR __Years = DISTINCT ( SELECTCOLUMNS ( __FullSelection, "dim_Date[Year Number]", dim_Date[Year Number] ) ) 
VAR __MonthsInYear = COUNTROWS( ALL(dim_Date[Month Name]) )
VAR __TopNYears = TOPN ( __N, __Years, dim_Date[Year Number], DESC ) 
VAR __ExtraYears = COUNTROWS ( __Years ) - __N 
VAR __ExtraString = IF(__ExtraYears &amp;gt; 0, " +" &amp;amp; __ExtraYears &amp;amp; " year(s)", "")
VAR __Delim1 = UNICHAR(10) &amp;amp; "     "
VAR __Delim2 = UNICHAR(10) 
RETURN 
    IF(ISFILTERED(dim_Date[Year Number]), 
        CONCATENATEX ( 
            __TopNYears, 
            VAR __CurrYear = dim_Date[Year Number] 
            VAR __CurrSelection = FILTER ( __FullSelection, dim_Date[Year Number] = __CurrYear ) 
            VAR __MonthCount = COUNTROWS ( __CurrSelection )
            VAR __ExtraMonths = __MonthCount - __N
            VAR __TopNMonths = TOPN ( __N, __CurrSelection , dim_Date[Month Number], ASC ) 
            VAR __Concat = 
                CONCATENATEX ( 
                    __TopNMonths, 
                    dim_Date[Month Short Name], 
                    __Delim1, 
                    dim_Date[Month Number], ASC ) 
            VAR __MonthText = 
            SWITCH ( 
                TRUE(), 
                __MonthCount = __MonthsInYear, "ALL", 
                __MonthCount &amp;gt; __N, __Concat &amp;amp; __Delim1 &amp;amp; "+" &amp;amp; __ExtraMonths, 
                __Concat ) 
            RETURN  
                dim_Date[Year Number] &amp;amp; " " &amp;amp; __MonthText, 
                __Delim2, 
                dim_Date[Year Number], DESC ) &amp;amp; __ExtraString, 
            "ALL Dates"
            )&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 20 Oct 2023 15:43:48 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Get-selected-values-from-Hierarchy-respecting-Hierarchy-Level/m-p/3488161#M133497</guid>
      <dc:creator>zoberender</dc:creator>
      <dc:date>2023-10-20T15:43:48Z</dc:date>
    </item>
    <item>
      <title>Re: Get selected values from Hierarchy respecting Hierarchy Level</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Get-selected-values-from-Hierarchy-respecting-Hierarchy-Level/m-p/3488205#M133499</link>
      <description>&lt;P&gt;I think you can move __MonthsInYear inside the outer CONCATENATX to resolve your remaining issue.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="php"&gt;Date Selection = 
VAR __N = 3
VAR __FullTable = SUMMARIZE ( ALL ( dim_Date ), dim_Date[Year Number], dim_Date[Month Short Name], dim_Date[Month Number] ) 
VAR __FullSelection = SUMMARIZE ( dim_Date, dim_Date[Year Number], dim_Date[Month Short Name], dim_Date[Month Number] ) 
VAR __Years = DISTINCT ( SELECTCOLUMNS ( __FullSelection, "dim_Date[Year Number]", dim_Date[Year Number] ) )
VAR __TopNYears = TOPN ( __N, __Years, dim_Date[Year Number], DESC ) 
VAR __ExtraYears = COUNTROWS ( __Years ) - __N 
VAR __ExtraString = IF(__ExtraYears &amp;gt; 0, " +" &amp;amp; __ExtraYears &amp;amp; " year(s)", "")
VAR __Delim1 = UNICHAR(10) &amp;amp; "     "
VAR __Delim2 = UNICHAR(10) 
RETURN 
    IF(ISFILTERED(dim_Date[Year Number]), 
        CONCATENATEX ( 
            __TopNYears, 
            VAR __CurrYear = dim_Date[Year Number]
            VAR __FullCurrYear = FILTER ( __FullTable, dim_Date[Year Number] = __CurrYear )
            VAR __CurrSelection = FILTER ( __FullSelection, dim_Date[Year Number] = __CurrYear )
            VAR __MonthsInYear = COUNTROWS ( __FullCurrYear )
            VAR __MonthCount = COUNTROWS ( __CurrSelection )
            VAR __ExtraMonths = __MonthCount - __N
            VAR __TopNMonths = TOPN ( __N, __CurrSelection , dim_Date[Month Number], ASC ) 
            VAR __Concat = 
                CONCATENATEX ( 
                    __TopNMonths, 
                    dim_Date[Month Short Name], 
                    __Delim1, 
                    dim_Date[Month Number], ASC ) 
            VAR __MonthText = 
            SWITCH ( 
                TRUE(), 
                __MonthCount = __MonthsInYear, "ALL", 
                __MonthCount &amp;gt; __N, __Concat &amp;amp; __Delim1 &amp;amp; "+" &amp;amp; __ExtraMonths, 
                __Concat ) 
            RETURN  
                dim_Date[Year Number] &amp;amp; " " &amp;amp; __MonthText, 
                __Delim2, 
                dim_Date[Year Number], DESC ) &amp;amp; __ExtraString, 
            "ALL Dates"
            )&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Edit: I've attached a sample pbix.&lt;/P&gt;</description>
      <pubDate>Mon, 13 Nov 2023 17:43:10 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Get-selected-values-from-Hierarchy-respecting-Hierarchy-Level/m-p/3488205#M133499</guid>
      <dc:creator>AlexisOlson</dc:creator>
      <dc:date>2023-11-13T17:43:10Z</dc:date>
    </item>
    <item>
      <title>Re: Get selected values from Hierarchy respecting Hierarchy Level</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Get-selected-values-from-Hierarchy-respecting-Hierarchy-Level/m-p/3488263#M133500</link>
      <description>&lt;P&gt;Thanks again&amp;nbsp;&lt;a href="javascript:void(0)" data-lia-user-mentions="" data-lia-user-uid="39298" data-lia-user-login="AlexisOlson" class="lia-mention lia-mention-user"&gt;AlexisOlson&lt;/a&gt;.&amp;nbsp; I think that did it for me on the Date side.&amp;nbsp; I may continue to tweak the delimeter's to get it to a place that's visually what I want.&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;I am going to go back and try to modify the code for the Business Unit selection.&amp;nbsp; This one may be a little more complicated as there are 3 levels (BU 1, 2 and 3) versus 2 levels for the Date (Year, Month).&amp;nbsp;&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;Hopefully I can take what you've provided as a template and apply it further!&amp;nbsp; I'll reach out if I run into any issues.&amp;nbsp; Thanks again!&lt;/P&gt;&lt;P&gt;Zac&lt;/P&gt;</description>
      <pubDate>Fri, 20 Oct 2023 16:36:50 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Get-selected-values-from-Hierarchy-respecting-Hierarchy-Level/m-p/3488263#M133500</guid>
      <dc:creator>zoberender</dc:creator>
      <dc:date>2023-10-20T16:36:50Z</dc:date>
    </item>
  </channel>
</rss>

