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

Power BI is turning 10! Let’s celebrate together with dataviz contests, interactive sessions, and giveaways. Register now.

Reply
Anonymous
Not applicable

DAX - Total Value of a measure is not correct

Hi guys,

 

I need your help please.

 

Based on the following sample :

SupplierProductdateSales
TOTOprd128/02/202369,785
TOTOprd228/02/202394,4
TOTOprd614/02/2023140
TOTOprd703/02/20232194,5312
TOTOprd803/02/202383,1528
TOTOprd918/01/2023246,1275
TOTOprd1018/01/2023279,7375
TOTOprd1416/01/2023477,5
TOTOprd1719/12/2022311,4475
TOTOprd1819/12/2022749,825
TATAprd128/02/20238150
TATAprd527/02/20232142,5
TATAprd627/02/20231467,5
TATAprd823/02/20239619,675
TATAprd921/02/2023775
TATAprd1016/02/20231885,71375
TATAprd1314/02/20231355
TATAprd1408/02/20235450
TATAprd1508/02/20232749,955
TATAprd2001/02/20232359,9895
TATAprd2131/01/2023470
TATAprd2331/01/2023750
TATAprd2625/01/2023190
TATAprd2725/01/2023920
TATAprd2823/01/2023687,5
TATAprd2923/01/20231030
TATAprd3319/01/20232469,989
TATAprd3419/01/20236473,48
TATAprd3512/01/20235883,44
TATAprd3605/01/20234669,958
TATAprd3727/12/2022575
TATAprd3827/12/2022325
TATAprd4020/12/2022946
TATAprd4513/12/20222027,399
TATAprd4602/12/20225883,455

 

Mohamed_59_0-1679394355985.png

I have created a measure :

Sales 3RM =
var _currentDate = MAX('Calendar'[Date])
return
CALCULATE(SUM(Data_Sample[Sales]),
    FILTER(ALLSELECTED('Calendar'),AND('Calendar'[Date]<= _currentDate , dateadd('Calendar'[Date],3,MONTH)>_currentDate)))
 

so I can see dynamically the rolling 3 last months sales for each supplier which works for each row.

Mohamed_59_1-1679394470735.png

However, the total shown is not correct, I should have 120 087,04.

 

Plus with the correct total (which I want to display on each row), I will be able to calculate the proportion of Sales 3RM per supplier on total Sales 3RM.

 

I tried to use a SUMX with a Summarize table but without any success.

 

Thank you !

2 ACCEPTED SOLUTIONS

@Anonymous 
I have no idea what does the result that you have obtained using my dax represent 😂

Please try

Sales 3RM =
VAR _currentDate =
    MAX ( 'Calendar'[Date] )
RETURN
    CALCULATE (
        SUM ( Data_Sample[Sales] ),
        FILTER (
            ALLSELECTED ( 'Calendar' ),
            AND (
                'Calendar'[Date] <= _currentDate,
                DATEADD ( 'Calendar'[Date], 3, MONTH ) > _currentDate
            )
        ),
        ALLSELECTED ( Data_Sample[Supplier] )
    )

View solution in original post

Anonymous
Not applicable

@tamerj1 

Your question give me the answer !

 

I replace the value on the ALLSELECTED function by the Supplier in the table Supplier and it works !!

Total Sales 3RM =
VAR _currentDate =
    MAX ( 'Calendar'[Date] )
RETURN
    CALCULATE (
        SUM ( Data_Sample[Sales] ),
        FILTER (
            ALLSELECTED ( 'Calendar' ),
            AND (
                'Calendar'[Date] <= _currentDate,
                DATEADD ( 'Calendar'[Date], 3, MONTH ) > _currentDate
            )
        ),
        ALLSELECTED ( Supplier[Supplier])
    )
Mohamed_59_0-1679411776934.png

 

Thank you very much 😉 

 

Have a nice day.

View solution in original post

11 REPLIES 11
ValtteriN
Super User
Super User

Hi,

This is a common question. Basically what is happening is that the total row calculates the dax you are using but with "empty" filter context. I recommend reading this article: Obtaining accurate totals in DAX - SQLBI

One of the more common solutions I use is to check for total row filter conext and use different calculation logic there e.g. IF(
isblank(MAX('table'[supplier])), [total row measure],
[normal measure])

I hope this post helps to solve your issue and if it does consider accepting it as a solution and giving the post a thumbs up!

My LinkedIn: https://www.linkedin.com/in/n%C3%A4ttiahov-00001/





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




tamerj1
Super User
Super User

Hi @Anonymous 
Please try

Sales 3RM =
SUMX (
    SUMMARIZE ( Data_Sample, Data_Sample[Supplier], 'Calendar'[YearMonth] ),
    VAR _currentDate =
        CALCULATE ( MAX ( 'Calendar'[Date] ) )
    RETURN
        CALCULATE (
            SUM ( Data_Sample[Sales] ),
            FILTER (
                ALLSELECTED ( 'Calendar' ),
                AND (
                    'Calendar'[Date] <= _currentDate,
                    DATEADD ( 'Calendar'[Date], 3, MONTH ) > _currentDate
                )
            )
        )
)
Anonymous
Not applicable

Thank you very much for your response @tamerj1 

 

But what I really need is to have the total "Sales 3RM" (63 084.93 for the selection made in the following exemple) for each supplier on each row.

For exemple : 

Mohamed_59_0-1679406721748.png

The result expected is in the last column.

 

Did you know how to do this ?

 

Sorry, I should have been more precise in my explanation.

@Anonymous 
Please try

Sales 3RM =
SUMX (
    CALCULATETABLE (
        SUMMARIZE ( Data_Sample, Data_Sample[Supplier], 'Calendar'[YearMonth] ),
        ALLSELECTED ( Data_Sample[Supplier] )
    ),
    VAR _currentDate =
        CALCULATE ( MAX ( 'Calendar'[Date] ) )
    RETURN
        CALCULATE (
            SUM ( Data_Sample[Sales] ),
            FILTER (
                ALLSELECTED ( 'Calendar' ),
                AND (
                    'Calendar'[Date] <= _currentDate,
                    DATEADD ( 'Calendar'[Date], 3, MONTH ) > _currentDate
                )
            )
        )
)
Anonymous
Not applicable

I tried this measure @tamerj1 :

Mohamed_59_0-1679407429032.png

But it's not the result I expect.

 

What I want is the following result (last column) :

Mohamed_59_0-1679406721748.png

It's the total sum of the 3rd column obtained by the measure :

Sales 3RM =
var _currentDate = MAX('Calendar'[Date])
return
CALCULATE(SUM(Data_Sample[Sales]),
    FILTER(ALLSELECTED('Calendar'),AND('Calendar'[Date]<= _currentDate , dateadd('Calendar'[Date],3,MONTH)>_currentDate)))

 

@Anonymous 
I have no idea what does the result that you have obtained using my dax represent 😂

Please try

Sales 3RM =
VAR _currentDate =
    MAX ( 'Calendar'[Date] )
RETURN
    CALCULATE (
        SUM ( Data_Sample[Sales] ),
        FILTER (
            ALLSELECTED ( 'Calendar' ),
            AND (
                'Calendar'[Date] <= _currentDate,
                DATEADD ( 'Calendar'[Date], 3, MONTH ) > _currentDate
            )
        ),
        ALLSELECTED ( Data_Sample[Supplier] )
    )
Anonymous
Not applicable

@tamerj1 

 

I will try to be more precise ^^

 

Below, in the 3rd column is the result of the measure you just gave me ("Sales 3RM") :

Mohamed_59_1-1679409485144.png

But What I need is in the color red, in the last column which is the total of each value of the measure you just gave me.

@Anonymous 

I understand what is your expected results. The matter is that I wasn't able to successfully obtain it so far. 
The [Supplier] column that you are using in the table visual is from which table?

Anonymous
Not applicable

Ok @tamerj1 

The supplier column comes from a Supplier table I have created using DAX :

Mohamed_59_0-1679410633928.png

 

Anonymous
Not applicable

@tamerj1 

Your question give me the answer !

 

I replace the value on the ALLSELECTED function by the Supplier in the table Supplier and it works !!

Total Sales 3RM =
VAR _currentDate =
    MAX ( 'Calendar'[Date] )
RETURN
    CALCULATE (
        SUM ( Data_Sample[Sales] ),
        FILTER (
            ALLSELECTED ( 'Calendar' ),
            AND (
                'Calendar'[Date] <= _currentDate,
                DATEADD ( 'Calendar'[Date], 3, MONTH ) > _currentDate
            )
        ),
        ALLSELECTED ( Supplier[Supplier])
    )
Mohamed_59_0-1679411776934.png

 

Thank you very much 😉 

 

Have a nice day.

@Anonymous 

Exactly

Helpful resources

Announcements
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 Power BI Update Carousel

Power BI Monthly Update - June 2025

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

June 2025 community update carousel

Fabric Community Update - June 2025

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