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

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.

Reply
AI14
Helper III
Helper III

calculate sum of if measure

Hi

 

How can i calculate sum of if measure - atm its adding 1 if true but its not summing total or even if i add to a graph it shows as 1 when it should be 5 for example

 

AI14_0-1676551160084.png

 

1 ACCEPTED SOLUTION

@AI14 
Please let me explain. 

The IF statement measure is non-additive measure. In PowerBi the total cell is evaluated just the same as any other cell (it is NOT the sum of the cells above). In fact the total cell is just another cell with different filter context (or no filter context in case of a table visual total or a matrix's grand total).

Usually non-additive measures are not supposed to be additive such as averages and percentages. For example if I have a measure that calculates the price per unit for different stores ($/unit), summing this measure for different stores to get a total has absolutely no meaning.

However, in your case this total is required and has meaning therefore, we need to force additivity. But forcing additivity depends on the filter context of the visual (the SUMMARIZECOLUMNS table created by power bi when you place the columns in the table visual). We need to manually create this table, iterate over it in order to sum the visible values in the visual.

I still don't have a clear idea about what you have there in the visual and the relationships between the different tables involved however, it would be something like

Duration Breach > =
SUMX (
    SUMMARIZE (
        FactTable,
        DimTable1[Column1],
        DimTable2[Column2],
        DimTable3[Column3]
    ),
    CALCULATE (
        IF (
            SUMX ( CLEAN_LIVE, CLEAN_LIVE[LiveCleanTime] )
                > SUMX ( 'Task Rules', 'Task Rules'[Duration] ),
            1
        )
    )
)

 

 

 

 

View solution in original post

6 REPLIES 6
tamerj1
Super User
Super User

Hi @AI14 
Which measure? Would you please indicate in the screenshot? And which column(s) are used to slice by in this table visual?

Hi

these are measures i created and put in a table.

 

AI14_1-1676557476997.png

 

1st measure:

Duration Breach >= IF(
    SUMX(CLEAN_LIVE,CLEAN_LIVE[LiveCleanTime]) > SUMX('Task Rules','Task Rules'[Duration]), 1)
 
2nd Measure
Duration Breach <= IF(
    SUMX(CLEAN_LIVE,CLEAN_LIVE[LiveCleanTime]) < SUMX('Task Rules','Task Rules'[Duration]), 1)
 
3rd Measure 
Finish Late =
IF ( [Finish-STD] > SUMX ( 'Task Rules', 'Task Rules'[Latest End] ), 1 )
 
4th Measure:
Duration+Late = IF(AND(
    [Duration Breach >] = 1 , [Finish Late] = 1),2)
 
These Measures add a 1 or 2 (4th measure) if statement true however its not summing.

@AI14 

Thank you

at the very right of the table you have a column [Start of H.... apparently you have other columns to the left, whatare they? From which tables? Whare the relationships between the tables?

using 3 different tables all have active relationships, either 1-2-many or many-2-many, the rest are measures.

 

the calculations are correct and the measures are working correctly but not counting the amount of times the statement is true

@AI14 
Please let me explain. 

The IF statement measure is non-additive measure. In PowerBi the total cell is evaluated just the same as any other cell (it is NOT the sum of the cells above). In fact the total cell is just another cell with different filter context (or no filter context in case of a table visual total or a matrix's grand total).

Usually non-additive measures are not supposed to be additive such as averages and percentages. For example if I have a measure that calculates the price per unit for different stores ($/unit), summing this measure for different stores to get a total has absolutely no meaning.

However, in your case this total is required and has meaning therefore, we need to force additivity. But forcing additivity depends on the filter context of the visual (the SUMMARIZECOLUMNS table created by power bi when you place the columns in the table visual). We need to manually create this table, iterate over it in order to sum the visible values in the visual.

I still don't have a clear idea about what you have there in the visual and the relationships between the different tables involved however, it would be something like

Duration Breach > =
SUMX (
    SUMMARIZE (
        FactTable,
        DimTable1[Column1],
        DimTable2[Column2],
        DimTable3[Column3]
    ),
    CALCULATE (
        IF (
            SUMX ( CLEAN_LIVE, CLEAN_LIVE[LiveCleanTime] )
                > SUMX ( 'Task Rules', 'Task Rules'[Duration] ),
            1
        )
    )
)

 

 

 

 

Amazing, Works like a charm !!

 

thanks for the explanation too, made alot of difference👍

 

 

Helpful resources

Announcements
July PBI25 Carousel

Power BI Monthly Update - July 2025

Check out the July 2025 Power BI update to learn about new features.

Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 community update carousel

Fabric Community Update - June 2025

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