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

Grow your Fabric skills and prepare for the DP-600 certification exam by completing the latest Microsoft Fabric challenge.

Reply
DataScope
New Member

DAX Calculate, Sum, Datesbetween duplicate date error

I would like to calculate sales for the specific time period (1/1/2021 to 1/31/2021) but keep receiving an error. My data contains a facts table named sales_order_item. Sales_order_item has a row for each item in a sales order, as well as that item's corresponding sale_price. So multiple rows can have the same order_id and same datetime timestamp.

 

I am using this dax function with a date table:

 

 

 

Promo Sales = CALCULATE(SUM(sales_order_item[sale_pricel]), DATESBETWEEN('Date Table'[Date], DATE(2021,01,01), DATE(2021,01,31)))

 

 

 

When that function is used, the result is blank. See screenshot below:

Blank data.png

 

I also tried to using only the sales order item table, with no other tables in the model. In that case the below DAX function is used, which references order date from the sales_item table instead of the date column from date table:

 

 

 

 Promo Sales = CALCULATE(SUM(sales_order_item[sale_pricel]), DATESBETWEEN('sales_order_item'[order_date], DATE(2021,01,01), DATE(2021,01,31)))

 

 

Error.png

 

The issue might have to do with the SUM aggregation within a CALCULATE function. But I don't know for sure and cannot figure out how to get the correct function. Any ideas?

 

1 ACCEPTED SOLUTION
v-xiaotang
Community Support
Community Support

Hi @DataScope 

vxiaotang_2-1647928944530.png

if you already have a specific date period, there is no need to use 'Date Table'. In this scenario, you can use the second measure, it calculates total by filter 'sales_order_item' in a period 
vxiaotang_0-1647928727472.png

Promo Sales 1 = CALCULATE(SUM(sales_order_item[sale_pricel]), filter('sales_order_item', 'sales_order_item'[order_date]>= DATE(2021,01,01) && 'sales_order_item'[order_date]<= DATE(2021,01,31)))

Here's a post for your reference on when to use a calendar table, 

https://community.powerbi.com/t5/Desktop/Calendar-Table/m-p/1281928

 

 

Best Regards,

Community Support Team _Tang

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

View solution in original post

4 REPLIES 4
v-xiaotang
Community Support
Community Support

Hi @DataScope 

vxiaotang_2-1647928944530.png

if you already have a specific date period, there is no need to use 'Date Table'. In this scenario, you can use the second measure, it calculates total by filter 'sales_order_item' in a period 
vxiaotang_0-1647928727472.png

Promo Sales 1 = CALCULATE(SUM(sales_order_item[sale_pricel]), filter('sales_order_item', 'sales_order_item'[order_date]>= DATE(2021,01,01) && 'sales_order_item'[order_date]<= DATE(2021,01,31)))

Here's a post for your reference on when to use a calendar table, 

https://community.powerbi.com/t5/Desktop/Calendar-Table/m-p/1281928

 

 

Best Regards,

Community Support Team _Tang

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

DataScope
New Member

@amitchandak Yes, a value was returned with your DAX code.

@amitchandak what exactly is going on here? Why does FILTER work when DATESBETWEEN does not?

amitchandak
Super User
Super User

@DataScope , first check does this give any data


Promo Sales = CALCULATE(SUM(sales_order_item[sale_pricel]), filter('sales_order_item', 'sales_order_item'[order_date]>= DATE(2021,01,01) && 'sales_order_item'[order_date]<= DATE(2021,01,31)))

 

Use this on new blank page and check. To avoid having any filter

Helpful resources

Announcements
RTI Forums Carousel3

New forum boards available in Real-Time Intelligence.

Ask questions in Eventhouse and KQL, Eventstream, and Reflex.

MayPowerBICarousel

Power BI Monthly Update - May 2024

Check out the May 2024 Power BI update to learn about new features.