Click here to Skip to main content
15,889,808 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I want to calculate total sales for all dates in a table where the date is less that a specific date. The specific date is stored in another measure.

What I have tried:

TotSales = 

/* Does not work if filtering using a pre-existing measure called [EndOfWeekDate] */
/*var FilteredTable = FILTER('Sales', 'Sales'[CYDate] < [EndOfWeekDate])*/

/* But it works if I hard code a date */
var FilteredTable = FILTER('Sales', 'Sales'[CYDate] < DATE(2024,17,7))

RETURN 

IF(
    
    SUM('Sales'[Sales]) = 0, 

    BLANK(),

    CALCULATE (SUM('Sales'[Sales]),  FilteredTable)

)
Posted
Comments
M-Badger 18-Apr-24 7:02am    
In the hardcoded version the month and the day seem to be reversed, it's DATE(Year, Month, Day) - hence DATE(2024,17,7) is the 7th day of the 17th month of the year 2024.
What is the format of [EndOfWeekDate] ?
AndyW1969 18-Apr-24 7:10am    
thanks for your reply. Here's the measure syntax. I can display this measure in a card visual and it shows the correct date value.

EndOfWeekDate = CALCULATE(max('Calendar'[Date]),'Calendar'[IsWeeklyReportWeek]=TRUE())
M-Badger 18-Apr-24 8:39am    
What does that expression evaluate as ? Does it return a value that PowerBI recognises as a date ?
AndyW1969 18-Apr-24 9:22am    
Yes it evaluates to a date of the format dd/mm/yyyy, with a value of 13/04/2024
M-Badger 18-Apr-24 9:24am    
Does DATE(2024/04/13) evaluate to the same thing ?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900