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
SasoosaS
Regular Visitor

DAX Measure for New Customer Sales Incorrectly Aggregating in Grand Total

Hello Power BI Community,

I am experiencing a problem with a DAX measure that calculates new customer sales. The measure works correctly at the row level of my visuals but it's not returning the expected value in the total line.

 

Here's the DAX code I'm using:

 

New Customer Sales Value =
VAR CustomerTM = VALUES(Sales[partner_count_code])
VAR PriorCustomers = CALCULATETABLE(
    VALUES(Sales[partner_count_code]),
    FILTER(
        ALL(DateTable),
        DateTable[Date] > MIN(DateTable[Date]) - churnTimeFrame[churnTimeFrame Value] &&
        DateTable[Date] < MIN(DateTable[Date])
    )
)
VAR NewCustomers = EXCEPT(CustomerTM, PriorCustomers)
RETURN
CALCULATE(
    SUM(Sales[total_selling_price]),
    FILTER(
        Sales,
        Sales[partner_count_code] IN NewCustomers
    )
)
 
 

In the PriorCustomers variable, I'm using MIN(DateTable[Date]) to find the earliest date, but I suspect this might be causing the issue when it comes to calculating the grand total. It appears that this function returns the earliest date in the entire DateTable in the context of the total row, rather than the earliest date in the context of each row.

 

I have also created my DateTable using DAX with the following code:
DateTable =
ADDCOLUMNS (
CALENDAR(MINX(Sales, sales[doc_date]),MAXX(Sales, sales[doc_date])),
"DateAsInteger", FORMAT ( [date], "YYYYMMDD" ),
 "Year", YEAR ( [date] ), "MonthNo", FORMAT ( [date], "MM" ),
"YearMonthNo", FORMAT ( [date], "YYYY/MM" ),
"YearMonth", FORMAT ( [date], "YYYY/mmm" ),
"MonthShort", FORMAT ( [date], "mmm" ),
"MonthLong", FORMAT ( [date], "mmmm" ),
"WeekNo", WEEKDAY ( [date] ),
"WeekDay", FORMAT ( [date], "dddd" ),
"WeekDayShort", FORMAT ( [date], "ddd" ),
"Quarter", "Q" & FORMAT ( [date], "Q" ),
"YearQuarter", FORMAT ( [date], "YYYY" ) & "/Q" & FORMAT ( [date], "Q" ))

 

My sales data is related to the DateTable with a many-to-one relationship (sales.doc_date > DateTable.date). My sales table contains a field partner_count_code that identifies each customer, and total_selling_price to represent the sales amount.

When I create a visual that includes the New Customer Sales Value measure, the total row seems to be aggregating the entire total sales, not just the sales for new customers. I've even manually checked and found that even when filters are applied, the total is still incorrect.

dax_total_1.png

Could anyone advise me on how to adjust my DAX formula to calculate the correct total for new customer sales regardless of the filter context?

1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi @SasoosaS ,

 

You can create a new measure to place on the visual object.

_New Customer Sales Value = SUMX(VALUES('DateTable'[YearMonth]),[New Customer Sales Value])

If the above one can't help you get the desired result, please provide some sample data in your tables (exclude sensitive data) with Text format and your expected result with backend logic and special examples. It is better if you can share a simplified pbix file. Thank you.

 

Best Regards,

Neeko Tang

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
Anonymous
Not applicable

Hi @SasoosaS ,

 

You can create a new measure to place on the visual object.

_New Customer Sales Value = SUMX(VALUES('DateTable'[YearMonth]),[New Customer Sales Value])

If the above one can't help you get the desired result, please provide some sample data in your tables (exclude sensitive data) with Text format and your expected result with backend logic and special examples. It is better if you can share a simplified pbix file. Thank you.

 

Best Regards,

Neeko Tang

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

Hi @Anonymous, 

 

Thank you for your solution.

The new measure you suggested works perfectly and has resolved my issue.

 

_New Customer Sales Value = SUMX(VALUES('DateTable'[YearMonth]),[New Customer Sales Value])

 

Your help is greatly appreciated. Thank you!

 

Best Regards,

Sašo

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.