Forum Discussion

akhilduvvuru's avatar
akhilduvvuru
Helper IV
3 years ago
Solved

Add custom Total row

Hi, I have a requirement to add custom total row in Power BI table visual   Source Data: DIM_TABLE ID Category 1 Apple 2 Orange 3 Fruits Total 4 Pen 5 Scale 6 Ink Po...
  • jdbuchanan71's avatar
    3 years ago

    akhilduvvuru 

    We have to break the link when calculating the total which we can do using REMOVEFILTER like this.

     

    Sales with total = 
    VAR _Category = SELECTEDVALUE ( DIM_TABLE[Category] )
    RETURN
        SWITCH (
            TRUE (),
            _Category = "Fruits Total",     CALCULATE (
                                                SUM ( FACT_TABLE[SalesAmount] ),
                                                REMOVEFILTERS ( DIM_TABLE ),
                                                DIM_TABLE[Category] IN { "Apple", "Orange" } ),
            _Category = "Stationary Total", CALCULATE (
                                                SUM ( FACT_TABLE[SalesAmount] ),
                                                REMOVEFILTERS ( DIM_TABLE ),
                                                DIM_TABLE[Category] IN { "Pen", "Scale", "Ink Pot" } ),
            _Category = "Clothing Total",   CALCULATE (
                                                SUM ( FACT_TABLE[SalesAmount] ),
                                                REMOVEFILTERS ( DIM_TABLE ),
                                                DIM_TABLE[Category] IN { "Shirt", "Pant" } ),
            SUM ( FACT_TABLE[SalesAmount] )
        )