Forum Discussion

evebarratt's avatar
evebarratt
Icon for Helper I rankHelper I
4 years ago
Solved

Incorrect Total using Sum, Sumx, and IF Dax

Hi, I have below dataset and table visual.

   

 

 

I got incorrect total from 'Price-GST(Wrong)' measure.

 

Price-GST(wrong) = 
VAR withoutGST = SUM('Table'[Price])
VAR withGST = SUMX(VALUES('Table'[ID]),withoutGST/1.1)
RETURN
IF(SELECTEDVALUE('Table'[GST])=0,withoutGST,withGST)

 

 

So I researched and was able to have the correct total from 'Price-GST(Correct)' mesaure. 

 

Price-GST(correct) = SUMX(VALUES('Table'[ID]),[Price-GST(wrong)])

 

 

However, i tried to combine those 2 measures into one using VAR but couldn't get what I wanted. Is there any way I can use one measure and still get the correct total?

  • Hi,

    Please try the below measure.

     

    New measure: =
    SUMX (
        ADDCOLUMNS (
            VALUES ( Data[ID] ),
            "@condition",
                IF (
                    CALCULATE ( SELECTEDVALUE ( Data[GST] ) ) = 0,
                    CALCULATE ( SUM ( Data[Price] ) ),
                    CALCULATE ( SUM ( Data[Price] ) ) / 1.1
                )
        ),
        [@condition]
    )

2 Replies

  • Hi,

    Please try the below measure.

     

    New measure: =
    SUMX (
        ADDCOLUMNS (
            VALUES ( Data[ID] ),
            "@condition",
                IF (
                    CALCULATE ( SELECTEDVALUE ( Data[GST] ) ) = 0,
                    CALCULATE ( SUM ( Data[Price] ) ),
                    CALCULATE ( SUM ( Data[Price] ) ) / 1.1
                )
        ),
        [@condition]
    )