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 September 15. Request your voucher.

Reply
LewisB
Frequent Visitor

Totals adding up incorrectly in measure but not in column

I have a calculated column that works fine, and ended up converting it into a measure.

This is the calculated column:

x-Updated Sales Switch = SWITCH(

    True(),

    '# Sales'[Company Code] = "pus" && '# Sales'[Invoice Date] >= DATE (2023,01,01) && '# Sales'[Invoice Date] <= DATE (2023,03,31), '# Sales'[Net Sales Amount]*1.4997,

    '# Sales'[Company Code] = "pus" && '# Sales'[Invoice Date] >= DATE (2022,10,01) && '# Sales'[Invoice Date] <= DATE (2022,12,31), '# Sales'[Net Sales Amount]*1.5302,

    '# Sales'[Net Sales Amount])

 
And this is the measure:

x-Updated Sales Measure = SUMX('# Sales',SWITCH(

    True(),

   SELECTEDVALUE('# Sales'[Company Code]) = "pus" && SELECTEDVALUE('# Sales'[Invoice Date])  >= DATE(2023,01,01) && SELECTEDVALUE('# Sales'[Invoice Date]) <= DATE(2023,03,31), SUMX('# Sales', '# Sales'[Net Sales Amount] * 1.4997),

    SELECTEDVALUE('# Sales'[Company Code]) = "pus" && SELECTEDVALUE('# Sales'[Invoice Date]) >= DATE(2022,10,01) && SELECTEDVALUE('# Sales'[Invoice Date]) <= DATE(2022,12,31), SUMX('# Sales', '# Sales'[Net Sales Amount] * 1.5302),

    SUM('# Sales'[Net Sales Amount])

))
 
The measure is pulling through the correct amounts, however the totals are not adding up correctly. Here is a screenshot of the column and measure side by side:
 
Screenshot 2023-02-23 095636.png

 



The measure seems to be multiplying the total by the number of lines in an invoice. This will have something to do with the SUMX function, as that calculates line by line, but I am unsure of how to solve this.


Are there any suggestions as to how I can go about fixing this? @amitchandak - you are familiar with my last issue, so you may be able to help here

1 ACCEPTED SOLUTION
v-jianboli-msft
Community Support
Community Support

Hi @LewisB ,

 

Based on your description, I have created a simple sample:

vjianbolimsft_1-1677204001699.png

Please try:

Measure =
VAR _a =
    ADDCOLUMNS (
        '# Sales',
        "C",
            SWITCH (
                TRUE (),
                '# Sales'[Company Code] = "pus"
                    && '# Sales'[Invoice Date] >= DATE ( 2023, 01, 01 )
                    && '# Sales'[Invoice Date] <= DATE ( 2023, 03, 31 ), '# Sales'[Net Sales Amount] * 1.4997,
                '# Sales'[Company Code] = "pus"
                    && '# Sales'[Invoice Date] >= DATE ( 2022, 10, 01 )
                    && '# Sales'[Invoice Date] <= DATE ( 2022, 12, 31 ), '# Sales'[Net Sales Amount] * 1.5302,
                '# Sales'[Net Sales Amount]
            )
    )
RETURN
    SUMX ( _a, [C] )

Final output:

vjianbolimsft_0-1677203961300.png

Best Regards,

Jianbo Li

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

2 REPLIES 2
v-jianboli-msft
Community Support
Community Support

Hi @LewisB ,

 

Based on your description, I have created a simple sample:

vjianbolimsft_1-1677204001699.png

Please try:

Measure =
VAR _a =
    ADDCOLUMNS (
        '# Sales',
        "C",
            SWITCH (
                TRUE (),
                '# Sales'[Company Code] = "pus"
                    && '# Sales'[Invoice Date] >= DATE ( 2023, 01, 01 )
                    && '# Sales'[Invoice Date] <= DATE ( 2023, 03, 31 ), '# Sales'[Net Sales Amount] * 1.4997,
                '# Sales'[Company Code] = "pus"
                    && '# Sales'[Invoice Date] >= DATE ( 2022, 10, 01 )
                    && '# Sales'[Invoice Date] <= DATE ( 2022, 12, 31 ), '# Sales'[Net Sales Amount] * 1.5302,
                '# Sales'[Net Sales Amount]
            )
    )
RETURN
    SUMX ( _a, [C] )

Final output:

vjianbolimsft_0-1677203961300.png

Best Regards,

Jianbo Li

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Thanks @v-jianboli-msft  - this worked for me!

Helpful resources

Announcements
August Power BI Update Carousel

Power BI Monthly Update - August 2025

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

August 2025 community update carousel

Fabric Community Update - August 2025

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