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

Grow your Fabric skills and prepare for the DP-600 certification exam by completing the latest Microsoft Fabric challenge.

Reply
Penguin12
New Member

Sum values only with a threshold based on header level

Hi!

I have this kind of data structure 

 

OrderHeaderOrderItemAmount
A1100
A2200
B5200
A3800
C41005

 

Now I need a DAX measure that only sums the Amount of the OrderItem when the sum of the header is bigger or equal then 1000. My idea was to first write a measure that always sums the amount for the header and then use it for filtering in another measure. But unfortunetly it did not work as intended. It basically filtered when the item was smaller then the threshold (1000) not the sum of the header level. 

 

How do I fix the first measure that it always, not depending on the context of the table, calculates the sum on the header level and checks if it is bigger then the threshold?

 

One example how it should be shown later

OrderItemAmount
1100
2200
3800
41005

 

1 ACCEPTED SOLUTION

Hi @Penguin12 ,

 

In this case, to reuse this logic in multiple measures in a performatic way, my suggestion is to create a calculated column in the original table to have the total for each header. For this you can use the same logic in the previous reply: 

NewColumn = 
CALCULATE (
    SUM ( 'Table'[Amount] ),
    ALLEXCEPT ( 'Table', 'Table'[OrderHeader] )
)​


Then you can use this column to filter as needed using CALCULATE/FILTER.

Otherwise, just use the variable below in each measure to calculate the table on the fly (the is no problem with this approach).

VAR _Table_Total_Header =
    ADDCOLUMNS (
        'Table',
        "Header_Total",
            CALCULATE (
                SUM ( 'Table'[Amount] ),
                ALLEXCEPT ( 'Table', 'Table'[OrderHeader] )
            )
    )

 

 

Hope this answer solves your problem!
If you need any additional help please @ me in your reply.
If my reply provided you with a solution, please consider marking it as a solution ✔️ or giving it a kudoe 👍

Thanks!

Best regards,
Joao Ribeiro

 

View solution in original post

3 REPLIES 3
Penguin12
New Member

@joaoribeiro thank you very much for reply! But is there a way to rather have it in two measures so I can use the second one for example in different contexts in tables instead of creating a new table? I have been struggeling with this and was not able to rewrite it

Hi @Penguin12 ,

 

In this case, to reuse this logic in multiple measures in a performatic way, my suggestion is to create a calculated column in the original table to have the total for each header. For this you can use the same logic in the previous reply: 

NewColumn = 
CALCULATE (
    SUM ( 'Table'[Amount] ),
    ALLEXCEPT ( 'Table', 'Table'[OrderHeader] )
)​


Then you can use this column to filter as needed using CALCULATE/FILTER.

Otherwise, just use the variable below in each measure to calculate the table on the fly (the is no problem with this approach).

VAR _Table_Total_Header =
    ADDCOLUMNS (
        'Table',
        "Header_Total",
            CALCULATE (
                SUM ( 'Table'[Amount] ),
                ALLEXCEPT ( 'Table', 'Table'[OrderHeader] )
            )
    )

 

 

Hope this answer solves your problem!
If you need any additional help please @ me in your reply.
If my reply provided you with a solution, please consider marking it as a solution ✔️ or giving it a kudoe 👍

Thanks!

Best regards,
Joao Ribeiro

 

joaoribeiro
Kudo Kingpin
Kudo Kingpin

Hi @Penguin12 ,

 

I think you use the following measure structure to solve your problem:

VAR _Table_Total_Header =
    ADDCOLUMNS (
        'Table',
        "Header_Total",
            CALCULATE (
                SUM ( 'Table'[Amount] ),
                ALLEXCEPT ( 'Table', 'Table'[OrderHeader] )
            )
    )
RETURN
    SUMX (
        FILTER ( '_Table_Total_Header', [Header_Total] >= 1000 ),
        'Table'[Amount]
    )

joaoribeiro_0-1701087219285.png

 

Hope this answer solves your problem!
If you need any additional help please @ me in your reply.
If my reply provided you with a solution, please consider marking it as a solution ✔️ or giving it a kudoe 👍

Thanks!

Best regards,
Joao Ribeiro

Helpful resources

Announcements
Europe Fabric Conference

Europe’s largest Microsoft Fabric Community Conference

Join the community in Stockholm for expert Microsoft Fabric learning including a very exciting keynote from Arun Ulag, Corporate Vice President, Azure Data.

RTI Forums Carousel3

New forum boards available in Real-Time Intelligence.

Ask questions in Eventhouse and KQL, Eventstream, and Reflex.

MayPowerBICarousel1

Power BI Monthly Update - May 2024

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