MDX: return last value for selected items in Power BI












0















This is a question regarding SSAS Cubes, MDX formulas and Power BI.



I have a measure with the active members per each month. So when I select for example 2018 it shouldn´t aggregate but return the last available month with active members, and if I break down by month it should give the active members for each month.



So I have this formula which works almost fine if querying in MS Management Studio:



with member [Measures].[Last existing SOCIOS] AS 
Max(
EXISTING [DIM FECHA].[Jerarquía].[MES NOMBRE].members,
iif([Measures].[ACTIVOS] = 0,null,
[Measures].[ACTIVOS])
)

select {[Measures].[Last existing SOCIOS]} on columns,
[DIM FECHA].[MES NOMBRE].members on rows
from [cubo_Compromisos]
where [DIM FECHA].[AÑO].&[2018]


enter image description here



I would prefer to have the november value returned at the 'All' level. But this is not my main problem. The real issue is that when I use this measure in Power BI it behaves differently: when selecting multiple months it ignores the selected values and just returns the last value for the whole year.



In the screenshot below I have added the value returned by the KPI Card because that is the value that I want returned:



enter image description here



If I select items like this it does it right, but I need it to select all months, and not just one because I am using this measure along others:



enter image description here



Does anyone know the right MDX function to use or an alternative?



Edited: 23-11-2018



It does the same in a Pivot Table connected to a SSAS Cube.When I add the date dimension to the table it works fine. But when using the date dimension and filtering it without the dimension added as rows it returns the value for the whole year.



enter image description here










share|improve this question





























    0















    This is a question regarding SSAS Cubes, MDX formulas and Power BI.



    I have a measure with the active members per each month. So when I select for example 2018 it shouldn´t aggregate but return the last available month with active members, and if I break down by month it should give the active members for each month.



    So I have this formula which works almost fine if querying in MS Management Studio:



    with member [Measures].[Last existing SOCIOS] AS 
    Max(
    EXISTING [DIM FECHA].[Jerarquía].[MES NOMBRE].members,
    iif([Measures].[ACTIVOS] = 0,null,
    [Measures].[ACTIVOS])
    )

    select {[Measures].[Last existing SOCIOS]} on columns,
    [DIM FECHA].[MES NOMBRE].members on rows
    from [cubo_Compromisos]
    where [DIM FECHA].[AÑO].&[2018]


    enter image description here



    I would prefer to have the november value returned at the 'All' level. But this is not my main problem. The real issue is that when I use this measure in Power BI it behaves differently: when selecting multiple months it ignores the selected values and just returns the last value for the whole year.



    In the screenshot below I have added the value returned by the KPI Card because that is the value that I want returned:



    enter image description here



    If I select items like this it does it right, but I need it to select all months, and not just one because I am using this measure along others:



    enter image description here



    Does anyone know the right MDX function to use or an alternative?



    Edited: 23-11-2018



    It does the same in a Pivot Table connected to a SSAS Cube.When I add the date dimension to the table it works fine. But when using the date dimension and filtering it without the dimension added as rows it returns the value for the whole year.



    enter image description here










    share|improve this question



























      0












      0








      0








      This is a question regarding SSAS Cubes, MDX formulas and Power BI.



      I have a measure with the active members per each month. So when I select for example 2018 it shouldn´t aggregate but return the last available month with active members, and if I break down by month it should give the active members for each month.



      So I have this formula which works almost fine if querying in MS Management Studio:



      with member [Measures].[Last existing SOCIOS] AS 
      Max(
      EXISTING [DIM FECHA].[Jerarquía].[MES NOMBRE].members,
      iif([Measures].[ACTIVOS] = 0,null,
      [Measures].[ACTIVOS])
      )

      select {[Measures].[Last existing SOCIOS]} on columns,
      [DIM FECHA].[MES NOMBRE].members on rows
      from [cubo_Compromisos]
      where [DIM FECHA].[AÑO].&[2018]


      enter image description here



      I would prefer to have the november value returned at the 'All' level. But this is not my main problem. The real issue is that when I use this measure in Power BI it behaves differently: when selecting multiple months it ignores the selected values and just returns the last value for the whole year.



      In the screenshot below I have added the value returned by the KPI Card because that is the value that I want returned:



      enter image description here



      If I select items like this it does it right, but I need it to select all months, and not just one because I am using this measure along others:



      enter image description here



      Does anyone know the right MDX function to use or an alternative?



      Edited: 23-11-2018



      It does the same in a Pivot Table connected to a SSAS Cube.When I add the date dimension to the table it works fine. But when using the date dimension and filtering it without the dimension added as rows it returns the value for the whole year.



      enter image description here










      share|improve this question
















      This is a question regarding SSAS Cubes, MDX formulas and Power BI.



      I have a measure with the active members per each month. So when I select for example 2018 it shouldn´t aggregate but return the last available month with active members, and if I break down by month it should give the active members for each month.



      So I have this formula which works almost fine if querying in MS Management Studio:



      with member [Measures].[Last existing SOCIOS] AS 
      Max(
      EXISTING [DIM FECHA].[Jerarquía].[MES NOMBRE].members,
      iif([Measures].[ACTIVOS] = 0,null,
      [Measures].[ACTIVOS])
      )

      select {[Measures].[Last existing SOCIOS]} on columns,
      [DIM FECHA].[MES NOMBRE].members on rows
      from [cubo_Compromisos]
      where [DIM FECHA].[AÑO].&[2018]


      enter image description here



      I would prefer to have the november value returned at the 'All' level. But this is not my main problem. The real issue is that when I use this measure in Power BI it behaves differently: when selecting multiple months it ignores the selected values and just returns the last value for the whole year.



      In the screenshot below I have added the value returned by the KPI Card because that is the value that I want returned:



      enter image description here



      If I select items like this it does it right, but I need it to select all months, and not just one because I am using this measure along others:



      enter image description here



      Does anyone know the right MDX function to use or an alternative?



      Edited: 23-11-2018



      It does the same in a Pivot Table connected to a SSAS Cube.When I add the date dimension to the table it works fine. But when using the date dimension and filtering it without the dimension added as rows it returns the value for the whole year.



      enter image description here







      ssas powerbi mdx






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Nov 23 '18 at 9:44







      vdBurg

















      asked Nov 20 '18 at 8:38









      vdBurgvdBurg

      22117




      22117
























          1 Answer
          1






          active

          oldest

          votes


















          0














          The function you are looking at is LastChild. Last Child on the upper level of the hierarchy will return the value you are looking at.



          I think that function can be used in the Cube design in SSAS - then this will be the standard behavior. If you want to do it with a query you need to do something like:




          SELECT [Date].[Fiscal].[Fiscal Quarter].[Q1 FY 2002].LastChild ON 0

          FROM [Adventure Works]




          To get the last month of the 1st quater (I used example from microsoft and another post on the subject )






          share|improve this answer























            Your Answer






            StackExchange.ifUsing("editor", function () {
            StackExchange.using("externalEditor", function () {
            StackExchange.using("snippets", function () {
            StackExchange.snippets.init();
            });
            });
            }, "code-snippets");

            StackExchange.ready(function() {
            var channelOptions = {
            tags: "".split(" "),
            id: "1"
            };
            initTagRenderer("".split(" "), "".split(" "), channelOptions);

            StackExchange.using("externalEditor", function() {
            // Have to fire editor after snippets, if snippets enabled
            if (StackExchange.settings.snippets.snippetsEnabled) {
            StackExchange.using("snippets", function() {
            createEditor();
            });
            }
            else {
            createEditor();
            }
            });

            function createEditor() {
            StackExchange.prepareEditor({
            heartbeatType: 'answer',
            autoActivateHeartbeat: false,
            convertImagesToLinks: true,
            noModals: true,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: 10,
            bindNavPrevention: true,
            postfix: "",
            imageUploader: {
            brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
            contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
            allowUrls: true
            },
            onDemand: true,
            discardSelector: ".discard-answer"
            ,immediatelyShowMarkdownHelp:true
            });


            }
            });














            draft saved

            draft discarded


















            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53389067%2fmdx-return-last-value-for-selected-items-in-power-bi%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown

























            1 Answer
            1






            active

            oldest

            votes








            1 Answer
            1






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes









            0














            The function you are looking at is LastChild. Last Child on the upper level of the hierarchy will return the value you are looking at.



            I think that function can be used in the Cube design in SSAS - then this will be the standard behavior. If you want to do it with a query you need to do something like:




            SELECT [Date].[Fiscal].[Fiscal Quarter].[Q1 FY 2002].LastChild ON 0

            FROM [Adventure Works]




            To get the last month of the 1st quater (I used example from microsoft and another post on the subject )






            share|improve this answer




























              0














              The function you are looking at is LastChild. Last Child on the upper level of the hierarchy will return the value you are looking at.



              I think that function can be used in the Cube design in SSAS - then this will be the standard behavior. If you want to do it with a query you need to do something like:




              SELECT [Date].[Fiscal].[Fiscal Quarter].[Q1 FY 2002].LastChild ON 0

              FROM [Adventure Works]




              To get the last month of the 1st quater (I used example from microsoft and another post on the subject )






              share|improve this answer


























                0












                0








                0







                The function you are looking at is LastChild. Last Child on the upper level of the hierarchy will return the value you are looking at.



                I think that function can be used in the Cube design in SSAS - then this will be the standard behavior. If you want to do it with a query you need to do something like:




                SELECT [Date].[Fiscal].[Fiscal Quarter].[Q1 FY 2002].LastChild ON 0

                FROM [Adventure Works]




                To get the last month of the 1st quater (I used example from microsoft and another post on the subject )






                share|improve this answer













                The function you are looking at is LastChild. Last Child on the upper level of the hierarchy will return the value you are looking at.



                I think that function can be used in the Cube design in SSAS - then this will be the standard behavior. If you want to do it with a query you need to do something like:




                SELECT [Date].[Fiscal].[Fiscal Quarter].[Q1 FY 2002].LastChild ON 0

                FROM [Adventure Works]




                To get the last month of the 1st quater (I used example from microsoft and another post on the subject )







                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Nov 20 '18 at 9:59









                Veselin DavidovVeselin Davidov

                5,5861515




                5,5861515






























                    draft saved

                    draft discarded




















































                    Thanks for contributing an answer to Stack Overflow!


                    • Please be sure to answer the question. Provide details and share your research!

                    But avoid



                    • Asking for help, clarification, or responding to other answers.

                    • Making statements based on opinion; back them up with references or personal experience.


                    To learn more, see our tips on writing great answers.




                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function () {
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53389067%2fmdx-return-last-value-for-selected-items-in-power-bi%23new-answer', 'question_page');
                    }
                    );

                    Post as a guest















                    Required, but never shown





















































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown

































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown







                    Popular posts from this blog

                    'app-layout' is not a known element: how to share Component with different Modules

                    android studio warns about leanback feature tag usage required on manifest while using Unity exported app?

                    WPF add header to Image with URL pettitions [duplicate]