Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
6 years ago
Solved

sum by comparing 3 columns

Hi All,   i have issue, where in i have to find the sum of sales by comparing other columns in the sames table. Please find the below sample   Table: Product     Sub product      Sales   Weight ...
  • jdbuchanan71's avatar
    6 years ago

    Hello Anonymous 

    Give this a try.

    Measure = 
    VAR _Blanks = CALCULATETABLE ( VALUES ( YourTable[Product] ), ALL ( YourTable ), ISBLANK ( YourTable[Weight] ) )
    RETURN 
    CALCULATE(
        SUM ( YourTable[Sales] ),
        KEEPFILTERS ( NOT YourTable[Product] IN ( _Blanks ) )
    )

  • jdbuchanan71's avatar
    jdbuchanan71
    6 years ago

    Anonymous 

    This gives me the expected result on the sample data and correct totaling as well.  Give it a try:

    Sum of Sales = 
    SUMX (
        VALUES ( 'Table'[Product] ),
        CALCULATE (
            VAR _Blanks =
                CALCULATETABLE (
                    FILTER (
                        ADDCOLUMNS (
                            CALCULATETABLE (
                                GROUPBY ( 'Table', 'Table'[Product], 'Table'[Sub Product] ),
                                'Table'[Category] <> "NA"
                            ),
                            "TheWeight", CALCULATE ( SUM ( 'Table'[Weight] ) )
                        ),
                        [TheWeight] = 0
                    ),
                    ALLEXCEPT ( 'Table', 'Table'[Product] ) )
            RETURN
                CALCULATE (
                    SUM ( 'Table'[Sales] ),
                    'Table'[Category] <> "NA",
                    FILTER ( 'Table', COUNTROWS ( _Blanks ) = BLANK () ) ) ) )