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

Be one of the first to start using Fabric Databases. View on-demand sessions with database experts and the Microsoft product team to learn just how easy it is to get started. Watch now

Reply
Anonymous
Not applicable

Change hierarchy level in matrix visualization

Hi!

 

I need to create a Matrix visual (or  a visual table looking that does the same thing) using 2 levels of hierarchy. This is the data:

 

Q3_data.JPG

 

And I need to display the total of all (that's easy), but below that just ONE of the companies (Nike in my example below) and then the cities, but showing the total amount including the items sold in the other company.

 

On the left you can see what I get, that it's Nike and within that level I have the cities, but what I want is the rigth picture that I made in excel as an example, which is one company and then the total per city in both nike and adidas.

 

Q3.JPG

 

Is there a way to make that possible?

 

Thank you in advance! 🙂 

 

1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi @Anonymous , 

Please refer to my pbix file to see if it helps you.

Create a measure.

Measure =
VAR _value =
    CALCULATE (
        SUM ( 'Table'[Value] ),
        FILTER (
            ALL ( 'Table' ),
            'Table'[City] = SELECTEDVALUE ( 'Table'[City] )
                && 'Table'[Label] = SELECTEDVALUE ( 'Table'[Label] )
        )
    )
VAR _NIKE =
    CALCULATE (
        SUM ( 'Table'[Value] ),
        FILTER (
            ALL ( 'Table' ),
            'Table'[Label] = SELECTEDVALUE ( 'Table'[Label] )
                && 'Table'[City] = SELECTEDVALUE ( 'Table'[City] )
        )
    )
VAR result =
    IF (
        HASONEVALUE ( 'Table'[City] )
            && MAX ( 'Table'[Company] ) = "NIKE",
        _NIKE,
        IF (
            HASONEVALUE ( 'Table'[City] )
                && MAX ( 'Table'[Company] ) = "Adidas",
            _NIKE,
            SELECTEDVALUE ( 'Table'[Value] )
        )
    )
VAR _a =
    CALCULATE (
        SUM ( 'Table'[Value] ),
        FILTER (
            ALL ( 'Table' ),
            'Table'[Label] = SELECTEDVALUE ( 'Table'[Label] )
                && 'Table'[Company] = SELECTEDVALUE ( 'Table'[Company] )
        )
    )
RETURN
    IF ( HASONEVALUE ( 'Table'[City] ), result, _a )

vpollymsft_0-1652086560216.png

 

If I have misunderstood your meaning, please provide more details with your desired output.

 

Best Regards

Community Support Team _ Polly

 

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

6 REPLIES 6
Anonymous
Not applicable

Hi @Anonymous , 

Please refer to my pbix file to see if it helps you.

Create a measure.

Measure =
VAR _value =
    CALCULATE (
        SUM ( 'Table'[Value] ),
        FILTER (
            ALL ( 'Table' ),
            'Table'[City] = SELECTEDVALUE ( 'Table'[City] )
                && 'Table'[Label] = SELECTEDVALUE ( 'Table'[Label] )
        )
    )
VAR _NIKE =
    CALCULATE (
        SUM ( 'Table'[Value] ),
        FILTER (
            ALL ( 'Table' ),
            'Table'[Label] = SELECTEDVALUE ( 'Table'[Label] )
                && 'Table'[City] = SELECTEDVALUE ( 'Table'[City] )
        )
    )
VAR result =
    IF (
        HASONEVALUE ( 'Table'[City] )
            && MAX ( 'Table'[Company] ) = "NIKE",
        _NIKE,
        IF (
            HASONEVALUE ( 'Table'[City] )
                && MAX ( 'Table'[Company] ) = "Adidas",
            _NIKE,
            SELECTEDVALUE ( 'Table'[Value] )
        )
    )
VAR _a =
    CALCULATE (
        SUM ( 'Table'[Value] ),
        FILTER (
            ALL ( 'Table' ),
            'Table'[Label] = SELECTEDVALUE ( 'Table'[Label] )
                && 'Table'[Company] = SELECTEDVALUE ( 'Table'[Company] )
        )
    )
RETURN
    IF ( HASONEVALUE ( 'Table'[City] ), result, _a )

vpollymsft_0-1652086560216.png

 

If I have misunderstood your meaning, please provide more details with your desired output.

 

Best Regards

Community Support Team _ Polly

 

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Anonymous
Not applicable

Hi @Anonymous 

 

Sorry for the late response. I couldn't check the code until now.

That's exactly what I wanted!! I didn't think it could be possible, you are brilliant!

I really appreciate that you have taken the time to help me. 😊

 

Thank you very much! 😊

parry2k
Super User
Super User

@Anonymous well should explain the logic based on sample data. as I asked, will the same happen for adidas?

 

 



Subscribe to the @PowerBIHowTo YT channel for an upcoming video on List and Record functions in Power Query!!

Learn Power BI and Fabric - subscribe to our YT channel - Click here: @PowerBIHowTo

If my solution proved useful, I'd be delighted to receive Kudos. When you put effort into asking a question, it's equally thoughtful to acknowledge and give Kudos to the individual who helped you solve the problem. It's a small gesture that shows appreciation and encouragement! ❤


Did I answer your question? Mark my post as a solution. Proud to be a Super User! Appreciate your Kudos 🙂
Feel free to email me with any of your BI needs.

Anonymous
Not applicable

Hi @parry2k 

 

Sorry, I didn't understand your question the first time (English is not my mother language).

Yes, for Adidas would the same, the total for adidas and then the cities would have the same result as it's the sum of both again (here a pic of the result)

 

Adidas.JPG

 

I hope I explained it properly now.

Thank you very much 🙂

parry2k
Super User
Super User

@Anonymous why there is no adidas in the expected output?

 

 

Follow us on LinkedIn and YouTube.gif to our YouTube channel

I would  Kudos if my solution helped. 👉 If you can spend time posting the question, you can also make effort to give Kudos to whoever helped to solve your problem. It is a token of appreciation!

 

Visit us at https://perytus.com, your one-stop shop for Power BI-related projects/training/consultancy.



Subscribe to the @PowerBIHowTo YT channel for an upcoming video on List and Record functions in Power Query!!

Learn Power BI and Fabric - subscribe to our YT channel - Click here: @PowerBIHowTo

If my solution proved useful, I'd be delighted to receive Kudos. When you put effort into asking a question, it's equally thoughtful to acknowledge and give Kudos to the individual who helped you solve the problem. It's a small gesture that shows appreciation and encouragement! ❤


Did I answer your question? Mark my post as a solution. Proud to be a Super User! Appreciate your Kudos 🙂
Feel free to email me with any of your BI needs.

Anonymous
Not applicable

Hi @parry2k 

 

This is an example. In my real data, I need to show a category that would be "Nike" here, to show the total items sold no matter the city. The cities that appear below, if you see, they are the sum of both Nike an adidas items sold. For instance, Madrid is 400 (100+300) in the first column (Alicia).

Thank you 🙂

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

ArunFabCon

Microsoft Fabric Community Conference 2025

Arun Ulag shares exciting details about the Microsoft Fabric Conference 2025, which will be held in Las Vegas, NV.

December 2024

A Year in Review - December 2024

Find out what content was popular in the Fabric community during 2024.