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
Gekko1
Helper I
Helper I

Incorrect Totals

My problem is as it follows: I have 2 tables, the first one has the amount of products per date and the company ID from where that product is; the second one has the company ID and the company name. In order to calculate the amount of products  that each company have in the last date of the selected month I wrote the Dax code as shown below:

AMOUNT = CALCULATE(SUM(ProductTable[AvailableAmount]),FILTER(ProductTable,ProductTable[EventDate]=MAX(ProductTable[EventDate])))

The tables have the format shown below:
Gekko1_0-1664371415673.png


When I put the Company Name as a row header in a matrix visual I am getting the wrong total. I've already tried the SUMMARIZE+SUMX, the IF+HASONFILTER and the SUMX methods but none of these actually worked. The DAX code of my attempts are listed below:

ATTEMPT1= SUMX(CompanyTable,CALCULATE(SUM(ProductTable[AvailableAmount]),FILTER(ProductTable,ProductTable[EventDate]=MAX(ProductTable[EventDate]))))

ATTEMPT2= 
VAR X = 
CALCULATE(SUM(ProductTable[AvailableAmount]),FILTER(ProductTable,ProductTable[EventDate]=MAX(ProductTable[EventDate]))))
RETURN
SUMX(SUMMARIZE(CompanyTable,CompanyTable[CompanyName]),X)

ATTEMPT3= 
VAR X =CALCULATE(SUM(ProductTable[AvailableAmount]),FILTER(ProductTable,ProductTable[EventDate]=MAX(ProductTable[EventDate]))))
RETURN
IF(HASONEFILTER(
CompanyTable[CompanyName]),X,SUMX(CompanyTable,X))
 
1 ACCEPTED SOLUTION
v-yadongf-msft
Community Support
Community Support

Hi @Gekko1 ,

 

If your goal is to calculate the amount of products  that each company have in the last date of the selected month, please try following steps:

 

This is my test table:

vyadongfmsft_0-1664435940151.png

 

vyadongfmsft_3-1664436337140.png

 

Create a new column:

Month = FORMAT([Date],"mmmm")

vyadongfmsft_1-1664435998093.png

 

Try following measure:

Measure = CALCULATE(
    SUM('Table'[Amount]),
        FILTER('Table','Table'[Month] = SELECTEDVALUE('Table'[Month]) && 
                        'Table'[Company ID] = SELECTEDVALUE('Table'[Company ID]) && 
                        'Table'[Date] = MAX('Table'[Date]))
                     )

 

Is this the result you want?

vyadongfmsft_2-1664436228621.png

 

Best regards,

Yadong Fang

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

1 REPLY 1
v-yadongf-msft
Community Support
Community Support

Hi @Gekko1 ,

 

If your goal is to calculate the amount of products  that each company have in the last date of the selected month, please try following steps:

 

This is my test table:

vyadongfmsft_0-1664435940151.png

 

vyadongfmsft_3-1664436337140.png

 

Create a new column:

Month = FORMAT([Date],"mmmm")

vyadongfmsft_1-1664435998093.png

 

Try following measure:

Measure = CALCULATE(
    SUM('Table'[Amount]),
        FILTER('Table','Table'[Month] = SELECTEDVALUE('Table'[Month]) && 
                        'Table'[Company ID] = SELECTEDVALUE('Table'[Company ID]) && 
                        'Table'[Date] = MAX('Table'[Date]))
                     )

 

Is this the result you want?

vyadongfmsft_2-1664436228621.png

 

Best regards,

Yadong Fang

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

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.