Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Find everything you need to get certified on Fabric—skills challenges, live sessions, exam prep, role guidance, and more. Get started

Reply
Take2
Regular Visitor

SUM Only Specified Values For All Higher Matrix Levels

Hello - 

 

Here is the link to the PBIX: 

https://drive.google.com/file/d/1vdZmj0n0-JpCXnQ6kqTgxxjGW_8x-rx8/view?usp=drive_link

 

The following Rows exist in the below Matrix:

- SalesRep Name

- Customer Name

- Product Name

 

Take2_0-1689950898749.png

 

ISSUE: The values highlighted in yellow are not correct.  Instead, they should be the SUM of Isolated Type 2 Desired Values ([z1 Isolate T2 Desired Values]).

 

DESIRED RESULT:

 

Take2_1-1689951330790.png

 

Measures are as follows:

Take2_2-1689951378455.png     

 

Take2_3-1689951399724.png

 

Take2_4-1689951463392.png

 

Take2_5-1689951501704.png

 

So the last measure [z1 Isolate T2 Desired Values] is correctly identifying the rows that should be SUMMED.

However, I am not able to figure out how to SUM these values for all higher levels in the Matrix.

 

Thanks for the help

1 ACCEPTED SOLUTION
tamerj1
Super User
Super User

@Take2 
Hi Nathan. Apologies for the late response. I really didn't have the time to look into it. Please look at the proposed solution below

1.png

Type 2 V2 New = 
VAR Type1Exists = NOT ISBLANK ( [Type 1] )
VAR Type2AllQuarters =
    SUMX ( 
        SUMMARIZE ( 
            Data,
            SalesRep[SalesRep Name],
            Customer[Customer Name],
            'Product'[Product Name]
        ),
        CALCULATE (
            [Type 2],
            REMOVEFILTERS ( 'Calendar'[Year Quarter Number] )
        )
    )
VAR Result = 
    IF ( Type1Exists, Type2AllQuarters )
RETURN 
    Result

View solution in original post

4 REPLIES 4
tamerj1
Super User
Super User

@Take2 
Hi Nathan. Apologies for the late response. I really didn't have the time to look into it. Please look at the proposed solution below

1.png

Type 2 V2 New = 
VAR Type1Exists = NOT ISBLANK ( [Type 1] )
VAR Type2AllQuarters =
    SUMX ( 
        SUMMARIZE ( 
            Data,
            SalesRep[SalesRep Name],
            Customer[Customer Name],
            'Product'[Product Name]
        ),
        CALCULATE (
            [Type 2],
            REMOVEFILTERS ( 'Calendar'[Year Quarter Number] )
        )
    )
VAR Result = 
    IF ( Type1Exists, Type2AllQuarters )
RETURN 
    Result

@tamerj1 

 

1) Please do not apologize for any delay.  I genuinely appreciate you getting back to me.

2) This is great!  Thank you very much for the help!

3) Trying to understand a bit more about your code .  From what I can see, the only difference in your code is that it adds SUMX & SUMMARIZE.

 

NOTE: Below is the real code modified according to your instructions, which is why the var & column names are changed.  It's working beautifully, thanks to you.

 

02 Installed Tamerj1 =

VAR WrittenExists = [Written Zeros STAGE] > 0

VAR InstalledAllQuarters =

    SUMX(

        SUMMARIZE(

            'FactWrittenSales STAGE',

            'DimSalesRep STAGE'[SalesPersonName],

            'DimCustomer STAGE'[CustomerName],

            'DimProduct STAGE'[PRODUCT_CODE]

        ),

        CALCULATE(

            [Installed Zeros STAGE],

            REMOVEFILTERS('DimCalendar STAGE'[FiscalQTRYearName])

        )

    )

VAR Result =

    IF(WrittenExists, InstalledAllQuarters)

RETURN

    Result

 

If I perform only the SUMMARIZE by itself in Dax Studio, it returns 39,705 rows for the 3 summarized columns (SalesPersonName, CustomerName, PRODUCT_CODE).

 

Does this mean that the SUMX iterates over all 39,705 rows, performing my CALCULATE statement for each row & then summing the total?

 

Or does it  mean that the SUMX iterates only over the rows in the current Filter Context of the matrix (a tiny subset of the 39,705 which only contains 3 PRODUCT_CODE values in this example)?

 

Regards,

Nathan

Take2
Regular Visitor

OK, so it looks like I still need help.  My solution in the previous post only works on the dummy data set I created for sharing.  However, when I try to add the same simple measure to the matrix in the REAL report, the Matrix just spins endlessly (more than 10 minutes), and Performance Analyzer just spins as well.

 

The spinning starts the instant I attempt to add the measure [z2 Totals] to the Matrix.

 

Take2_2-1689975875074.png

 

Take2_1-1689975807976.png

 

After spinning for 15 minutes, the matrix eventually fails:

"Cannot display the visual.  See Details."

 

Take2_3-1689975976461.png

 

I am confused how this can be running out of memory.

In the current FC (Filter Context), there are only 3 values for 'DimProduct STAGE'[PRODUCT_CODE] over which I want to be iterating.  So how am I running out of memory?

1) $18.89

2) $4.58

3) $6.87

 

If anyone can help me fix the measure so that it only handles the PRODUCT_CODE values displayed, I would greatly appreciate it.  This measure should take less than a second to process the resul.  So clearly my measure is very wrong....at least when performed against the real data set.

 

Thank you

Take2
Regular Visitor

Well, I finally figured it out.  Only took me most the day of trial & error.  Oh DAX.

 

Take2_2-1689971813244.png

 

 

Take2_1-1689971472255.png

 

Thanks to anyone who was trying to help me.

 

Helpful resources

Announcements
Sept PBI Carousel

Power BI Monthly Update - September 2024

Check out the September 2024 Power BI update to learn about new features.

September Hackathon Carousel

Microsoft Fabric & AI Learning Hackathon

Learn from experts, get hands-on experience, and win awesome prizes.

Sept NL Carousel

Fabric Community Update - September 2024

Find out what's new and trending in the Fabric Community.