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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
Titatovenaar2
Helper III
Helper III

DAX: Exclude Negatives in Totals in Higher Hierarchies in Matrix, But do Show Them on Lower Level

Hi everyone,

 

(.PBIX File included.)

I have a matrix with a SUMX measure inside that on a certain level in the hierarchy (i.e.: YearMonth-Plant-Material-Location) everything below zero gets rounded to 0.

This measure shows correct values when the Matrix is Rolled up, however, When I unfold the Matrix to its lowest level, I see that all negative records are rounded to 0. They should only round up to 0 on a higher level.

 

Below I show in green I show which measure is correct:

  • [Closing Stock] is correct when the Matrix is Unfolded.
  • [Closing Stock > 0] is correct when the Matrix is Rolled Up.

 

Titatovenaar2_0-1641228332003.png

The measure I currently use to ignore negative values on the level of YearMonth-Plant-Material-Location

 

Closing Stock > 0 = 
SUMX(
    SUMMARIZE('Fact Inventory', 
        'DIM Calendar'[YearMonth]
        ,'Fact Inventory'[Plant]
        ,'Fact Inventory'[Material]
        ,'Fact Inventory'[Location]
    )
    ,IF(
         [Closing Stock] < 0
        ,0
        ,[Closing Stock]
    )
)

 

The measure that shows values we would like to view on the level of YearMonth-Plant-Material-Location-Batch (the deepest level of the hierarchy)

 

Closing Stock = 
SUM('Fact Inventory'[Stock])

 

 

The dataset we use these measures on is the following table:

YearMonthBudat_dtmPlantMaterialLocationBatchMovement_GroupStock
2021-012021-01-04AUB111352 NULLR-1150.750
2021-012021-01-31AUB1113521000R000022425C-638.323
2021-012021-01-04AUB1113521000R000022425C-271.887
2021-012021-01-26AUB1113521000R000022425C-66.654
2021-012021-01-19AUB1113521000R000022425R648.900
2021-012021-01-12AUB111352 NULLR-525.550
2021-012021-01-03AUB1113521000R000022425C-896.953
2021-012021-01-12AUB1113521000R000022425R525.550
2021-012021-01-08AUB1113521000R000022425R559.250
2021-012021-01-09AUB1113521000R000022425C-404.594
2021-012021-01-07AUB1113521000R000022425C-232.933
2021-012021-01-18AUB1113521000R000022425C-222.433
2021-012021-01-06AUB1113521000R000022425C-231.428
2021-012021-01-08AUB111352 R000022425S525.550
2021-012021-01-05AUB1113521000R000022425C-269.349
2021-012021-01-20AUB1113521000R000022425C-218.707
2021-012021-01-12AUB111352 R000022425S724.250
2021-012021-01-18AUB111352 NULLR-724.250
2021-012021-01-22AUB1113521000R000022425R1001.100
2021-012021-01-24AUB1113521000R000022425C-724.731
2021-012021-01-21AUB1113521000R000022425C-146.519
2021-012021-01-03AUB1113521000R000022425C60.000
2021-012021-01-08AUB111352 NULLR-559.250
2021-012021-01-18AUB111352 R000022425S1001.100
2021-012021-01-25AUB1113521000R000022425C-249.267
2021-012021-01-13AUB111352 R000022425S648.900
2021-012021-01-22AUB111352 NULLR-1001.100
2021-012021-01-04AUB1113521000R000022425R1150.750
2021-012021-01-04AUB111352 R000022425S559.250
2021-012021-01-19AUB111352 NULLR-648.900
2021-012021-01-19AUB1113521000R000022425C-226.384
2021-012021-01-18AUB1113521000R000022425R724.250
2021-012021-01-01AUB1113521000R000022425OPENINGSTOCK1413.971
2021-012021-01-01AUB111352 R000022425OPENINGSTOCK1150.750
2021-012021-01-01AUB1140019999R000033331R4000
2021-012021-01-01AUB1140019999R000033332S-5000
2021-012021-01-01AUB1170055000R000066000R4000
2021-012021-01-01AUB1170053000R000066000S-5000

 

We are dealing with around 100 million records, so Performance is also something to keep in mind.

 

Is there a way to reveal negatives on the deepest level in a matrix, while rounding up on a different level?

 

Kind regards,

Igor

1 ACCEPTED SOLUTION
parry2k
Super User
Super User

@Titatovenaar2 you should ISINSCOPE function to find out what level you are at and then wrap your measure around it.

 

 

Closing Stock > 0 = 
IF ( ISINSCOPE ( YourTable[Product] ), //you are at product level
   [Closing Stock],

SUMX(
    SUMMARIZE('Fact Inventory', 
        'DIM Calendar'[YearMonth]
        ,'Fact Inventory'[Plant]
        ,'Fact Inventory'[Material]
        ,'Fact Inventory'[Location]
    )
    ,IF(
         [Closing Stock] < 0
        ,0
        ,[Closing Stock]
    )
)
)

 

 

You can change above if condition as you see fit.

 

Follow us on LinkedIn and subscribe to our YouTube channel

 

Learn about conditional formatting at Microsoft Reactor

My latest blog post The Power of Using Calculation Groups with Inactive Relationships (Part 1) (perytus.com) I would  Kudos if my solution helped. 👉 If you can spend time posting the question, you can also make efforts 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.

View solution in original post

4 REPLIES 4
aj1973
Community Champion
Community Champion

Hi @Titatovenaar2 

How about you keep it simple

aj1973_0-1641232086583.png

 

Regards
Amine Jerbi

If I answered your question, please mark this thread as accepted
and you can follow me on
My Website, LinkedIn and Facebook

parry2k
Super User
Super User

@Titatovenaar2 Awesome. glad it worked out, Subscribe to my YouTube channel where I will be posting uncommon tips and tricks. Cheers!!

 

Follow us on LinkedIn and subscribe to our YouTube channel

 

Learn about conditional formatting at Microsoft Reactor

My latest blog post The Power of Using Calculation Groups with Inactive Relationships (Part 1) (perytus.com) I would  Kudos if my solution helped. 👉 If you can spend time posting the question, you can also make efforts 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.

Titatovenaar2
Helper III
Helper III

Works like a charm. Epic functionality that I didn't know about yet. Thanks for the fast reply also!

parry2k
Super User
Super User

@Titatovenaar2 you should ISINSCOPE function to find out what level you are at and then wrap your measure around it.

 

 

Closing Stock > 0 = 
IF ( ISINSCOPE ( YourTable[Product] ), //you are at product level
   [Closing Stock],

SUMX(
    SUMMARIZE('Fact Inventory', 
        'DIM Calendar'[YearMonth]
        ,'Fact Inventory'[Plant]
        ,'Fact Inventory'[Material]
        ,'Fact Inventory'[Location]
    )
    ,IF(
         [Closing Stock] < 0
        ,0
        ,[Closing Stock]
    )
)
)

 

 

You can change above if condition as you see fit.

 

Follow us on LinkedIn and subscribe to our YouTube channel

 

Learn about conditional formatting at Microsoft Reactor

My latest blog post The Power of Using Calculation Groups with Inactive Relationships (Part 1) (perytus.com) I would  Kudos if my solution helped. 👉 If you can spend time posting the question, you can also make efforts 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.

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

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

April Fabric Community Update

Fabric Community Update - April 2024

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