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

The Power BI DataViz World Championships are on! With four chances to enter, you could win a spot in the LIVE Grand Finale in Las Vegas. Show off your skills.

Reply
nesselman
Helper I
Helper I

Calculating a SUM if Date is Less Table Date

What I'm trying to do is SUM all the Inventory if the CategoryEnding Date is <= the Weekending Date.

 

TABLE1 is a simple calendar

TABLE2 is a table with Ending Date and Inventory

NO Relationships (because that ties the dates together)

 

= CALCULATE(SUM([Inventory]),[CategoryEnding]<='TABLE1'[Weekending])

This gives "expecting a true/false

 

How can I write this DAX measure please?

 

TABLE1 TABLE2     
Weekending CategoryEndingInventory   
10/14/2022 10/28/2022$1,000    
10/21/2022 11/11/2022$5,000    
10/28/2022 11/18/2022$500    
11/4/2022 12/2/2022$7,500    
11/11/2022       
11/18/2022       
11/25/2022       
12/2/2022       
        
        
PBI Table       
WeekEndingTotal to CategoryEnding Notes    
10/14/2022$14,000 Since all Dates are > Weekending Date they SUM
10/21/2022$14,000      
10/28/2022$14,000      
11/4/2022$13,000 lose the 10/28 Category Ending 
11/11/2022$13,000      
11/18/2022$8,000 lose the 11/11 Category Ending 
11/25/2022$7,500 lose the 11/18 Category Ending 
12/2/2022$7,500      
12/9/2022$0 lose the 12/2 Category Ending  
1 ACCEPTED SOLUTION
amitchandak
Super User
Super User

@nesselman , if they are not related you can work on selected value or min or max

 

example

 

CALCULATE(SUM(Table2[Inventory]),filter(Table2, table2[CategoryEnding]<=max('TABLE1'[Weekending]) ))

Full Power BI Video 20 Hours YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

View solution in original post

3 REPLIES 3
Thennarasu_R
Responsive Resident
Responsive Resident

Measure= var A=CALCULATE(SUM([Inventory]),userelationship(CategoryEnding Date ,Weekending Date)
               Var Result=calculate(A,Filter(Table,Table(MinCategoryEnding Date)<=max(table,Weekending Date)
return
    result

amitchandak
Super User
Super User

@nesselman , if they are not related you can work on selected value or min or max

 

example

 

CALCULATE(SUM(Table2[Inventory]),filter(Table2, table2[CategoryEnding]<=max('TABLE1'[Weekending]) ))

Full Power BI Video 20 Hours YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

Yes, that worked using "max".  I needed it the other way so I used:

>=MAX

 

nesselman_0-1666169333153.png

 

 

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

FebPBI_Carousel

Power BI Monthly Update - February 2025

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

Feb2025 NL Carousel

Fabric Community Update - February 2025

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