Forum Discussion

mp390988's avatar
mp390988
Icon for Post Partisan rankPost Partisan
4 months ago
Solved

SUMMARISECOLUMNS ISSUE

Hello,

I am trying to create a summary table for revenue per year per month and the revenue per year.
I created the DAX table using the below code.

s1 = 
SUMMARIZECOLUMNS(
    DimCalendar[Year],
    DimCalendar[Month],
    FILTER(
        FactMain,
        FactMain[ColumnType] = "Revenue"
    ),
    "Revenue", [Total Rev],
    "Revenue Per Year",
        CALCULATE(
            [Total Rev],
            ALLEXCEPT(DimCalendar,DimCalendar[Year])
        )
)


But the issue I am having is that my "Revenue Per Year" field is making no sense as it is just simply returning the individual revenues when it should be returning the total revenue for that year. 


Any idea why this is happening?

Thank You!



 

 

  • Ok!

     

    Move the FactMain filter into your base measure instead, and keep SUMMARIZECOLUMNS clean:

    Step 1 : Redefine your base measure (or create a new one):

     

    Total Rev Revenue = 

    CALCULATE(

        [Total Rev],

        FactMain[ColumnType] = "Revenue"

    )

     

    Step 2 : Rebuild the table without the FILTER argument:

     

    s1 = 

    SUMMARIZECOLUMNS(

        DimCalendar[Year],

        DimCalendar[Month],

        "Revenue", [Total Rev Revenue],

        "Revenue Per Year",

            CALCULATE(

                [Total Rev Revenue],

                ALL(DimCalendar[Month])

            )

    )

     

    REMEMBER ME: Never use FILTER(FactTable,...) directly inside SUMMARIZECOLUMNS when you also need context manipulation in the same table. Always push those filters into your measures, this is the golden rule for avoiding this exact class of bugs.

  • Great news that it's working!

    The Blank Row Explained

    That blank row with 0.00 is a classic Power BI behaviour — it represents a "blank" member that SUMMARIZECOLUMNS automatically generates when there are rows in your FactMain table that do not match any row in DimCalendar.

    In other words, some fact rows have a date key that either:

    Is NULL / blank

    Points to a date that doesn't exist in your DimCalendar table

    So Power BI groups all those "unmatched" fact rows under a blank Year and blank Month bucket.

     

    To fix it, simply wrap your SUMMARIZECOLUMNS with FILTER to exclude blank years:

     

    s1 =
    FILTER(
    SUMMARIZECOLUMNS(
    DimCalendar[Year],
    DimCalendar[Month],
    "Revenue", [Total Rev],
    "Revenue Per Year", CALCULATE([Total Rev], ALLEXCEPT(DimCalendar, DimCalendar[Year]))
    ),
    NOT ISBLANK(DimCalendar[Year])
    )

  • mp390988's avatar
    mp390988
    4 months ago

    Hi oussamahaimoud ,

    Thank you for explaining the blank rows and you are right, my fact table does have rows where the date is blank. That explains it!

     

    Thank You! ðŸ™‚

  • Hi mp390988,

     

    Thank you for reaching out to Microsoft Fabric Community.

     

    Thank you oussamahaimoud for the prompt response.

     

    Yes, using the FILTER(FactMain, ...) directly inside SUMMARIZECOLUMNS is generally not considered as best practice, especially on large fact tables.

    The best approach is to move the filter logic into measures using CALCULATE and then use the measures inside SUMMARIZECOLUMNS:

    For example:

    Rev Filtered =
    CALCULATE(
        SUM(FactMain[GBPRevenue]),
        FactMain[ColumnType] = "Revenue",
        NOT ISBLANK(FactMain[TDMonth])
    )

     

    Vol Filtered =
    CALCULATE(
        SUM(FactMain[GBPVolume]),
        FactMain[ColumnType] = "Revenue",
        NOT ISBLANK(FactMain[TDMonth])
    )

     

    Now use the measures inside SUMMARIZECOLUMNS:

    AllClients =
    SUMMARIZECOLUMNS(
        FactMain[TDMonth],
        FactMain[TD Month Formatted],
        FactMain[TradeDate],
        FactMain[DealerGroup],
        FactMain[DealerID],
        FactMain[ClientID],
        FactMain[ClientName],
        FactMain[Product],
        "Rev", [Rev Filtered],
        "Vol", [Vol Filtered]
    )

    This approach is usually preferred because it improves the readability, reusability and overall query optimization.

     

    Thanks and regards,

    Anjan Kumar Chippa

14 Replies

  • Hi VijayP ,

    It is still not working.

     

    This is my semantic model, nothing extravagent going on here.
    All I can think of is that the DimCalendar[Month] is sorted by DimCalendar[MonthNumber].

     

    Thank You!

    • oussamahaimoud's avatar
      oussamahaimoud
      Icon for Memorable Member rankMemorable Member

      mp390988,

      You need to remove both the Month and MonthNumber filters explicitly:

       

      s1 = 

      SUMMARIZECOLUMNS(

          DimCalendar[Year],

          DimCalendar[Month],

          "Revenue", [Total Rev Revenue],

          "Revenue Per Year",

              CALCULATE(

                  [Total Rev Revenue],

                  ALL(DimCalendar[Month], DimCalendar[MonthNumber])

              )

      )

       

      Or even safer, just wipe the entire calendar filter and restore only Year:

       

      s1 = 

      SUMMARIZECOLUMNS(

          DimCalendar[Year],

          DimCalendar[Month],

          "Revenue", [Total Rev Revenue],

          "Revenue Per Year",

              CALCULATE(

                  [Total Rev Revenue],

                  ALL(DimCalendar),

                  VALUES(DimCalendar[Year])

              )

      )

      • mp390988's avatar
        mp390988
        Icon for Post Partisan rankPost Partisan

        Hi oussamahaimoud ,

        Sorry to bother you again but I was thinking with the following formula it is bad practice right to use the filter the way it has been done? What is the best way to write this using good practice please?


        AllClients = SUMMARIZECOLUMNS(
            FactMain[TDMonth],
            FactMain[TD Month Formatted],
            FactMain[TradeDate],
            FactMain[DealerGroup],
            FactMain[DealerID],
            FactMain[ClientID],
            FactMain[ClientName],
            FactMain[Product],
            FILTER(
                FactMain,
                FactMain[ColumnType] = "Revenue" && ISBLANK(FactMain[TDMonth])=FALSE()
            ),
            "Rev", sum(FactMain[GBPRevenue]),
            "Vol", sum(FactMain[GBPVolume])
        )

         

        Thank You,

        M

  • Hi mp390988,

    Hope you're doing well!

     

    SITUATION :

    The problem is that ALLEXCEPT inside SUMMARIZECOLUMNS doesn't behave as expected because SUMMARIZECOLUMNS already applies its own filter context for each row (both Year AND Month). The ALLEXCEPT tries to remove the Month filter, but the grouping context of SUMMARIZECOLUMNS overrides it, so it ends up returning the same value as the monthly Revenue.

     

    SOLUTION :

    I suggest to replace ALLEXCEPT with ALL(DimCalendar) combined with VALUES to reintroduce only the Year filter:

     

    s1 = 
    SUMMARIZECOLUMNS(
    DimCalendar[Year],
    DimCalendar[Month],
    FILTER(
    FactMain,
    FactMain[ColumnType] = "Revenue"
    ),
    "Revenue", [Total Rev],
    "Revenue Per Year",
    CALCULATE(
    [Total Rev],
    ALL(DimCalendar[Month])
    )
    )

     

    So, by using ALL(DimCalendar[Month]), you are explicitly removing the Month filter while keeping the Year grouping intact, which forces the calculation to aggregate across all months for that year.

     

    Approach What happening?

    ALLEXCEPT(DimCalendar, DimCalendar[Year])Gets overridden by SUMMARIZECOLUMNS row context → returns monthly value
    ALL(DimCalendar[Month])Explicitly clears only the Month filter → correctly sums all months per Year

     

    If your [Total Rev] measure itself involves complex filters, you may also consider creating the Revenue Per Year as a separate measure and referencing it in the table, as measures tend to handle filter context more predictably than inline CALCULATE expressions inside SUMMERIZECOLUMNS.

     

    Hope this helps. Feel free to ask me questions if needed, and don’t forget to like (kudos) & Accept as Solution if this guidance worked for you. That's motivate me to keep helping.

     

    Best regards,

    Oussama (Data Consultant & Fabric's Expert)

  • Hi oussamahaimoud ,

    Thank you for your reply.

     

    Unfortunately, it still hasn't fixed the issue although I tried your suggested approaches. 

     

    Approach 1

    s1 = 
    SUMMARIZECOLUMNS(
        DimCalendar[Year],
        DimCalendar[Month],
        FILTER(
            FactMain,
            FactMain[ColumnType] = "Revenue"
        ),
        "Revenue", [Total Rev],
        "Revenue Per Year",
            CALCULATE(
                [Total Rev],
                ALL(DimCalendar),
                VALUES(DimCalendar[Year])
            )
    )

     

    Approach 2

    s1 = 
    SUMMARIZECOLUMNS(
        DimCalendar[Year],
        DimCalendar[Month],
        FILTER(
            FactMain,
            FactMain[ColumnType] = "Revenue"
        ),
        "Revenue", [Total Rev],
        "Revenue Per Year",
            CALCULATE(
                [Total Rev],
                ALL(DimCalendar[Month])
            )
    )

     

     

    Thank You

    • oussamahaimoud's avatar
      oussamahaimoud
      Icon for Memorable Member rankMemorable Member

      Ok!

       

      Move the FactMain filter into your base measure instead, and keep SUMMARIZECOLUMNS clean:

      Step 1 : Redefine your base measure (or create a new one):

       

      Total Rev Revenue = 

      CALCULATE(

          [Total Rev],

          FactMain[ColumnType] = "Revenue"

      )

       

      Step 2 : Rebuild the table without the FILTER argument:

       

      s1 = 

      SUMMARIZECOLUMNS(

          DimCalendar[Year],

          DimCalendar[Month],

          "Revenue", [Total Rev Revenue],

          "Revenue Per Year",

              CALCULATE(

                  [Total Rev Revenue],

                  ALL(DimCalendar[Month])

              )

      )

       

      REMEMBER ME: Never use FILTER(FactTable,...) directly inside SUMMARIZECOLUMNS when you also need context manipulation in the same table. Always push those filters into your measures, this is the golden rule for avoiding this exact class of bugs.

      • mp390988's avatar
        mp390988
        Icon for Post Partisan rankPost Partisan

        Hi oussamahaimoud ,

         

        Thank you for your reply ðŸ™‚

         

        Your suggestion to remove the filter has now got it working as expected!!

         

         

        I do have one more question though, why is that row marked in the snapshot appearing? It has no year and no month?

         

        Thank You!

        #

         

        Thank You,

  • VijayP's avatar
    VijayP
    Icon for Community Champion rankCommunity Champion

    mp390988  I have used a proper model and used the same measure 

    s1 = SUMMARIZECOLUMNS(
        Dates[Year],
        Dates[Month],
        FILTER(
          'Application',
           'Application'[Application] = "Excel"
        ),
        "Revenue", [Total Revenue],
        "Revenue Per Year",
            CALCULATE(
                [Total Revenue],
                ALLEXCEPT(Dates,Dates[Year])
            )
    )
    that is working fine! 
    My suggestion check your semantic model again!