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

Join us for an expert-led overview of the tools and concepts you'll need to become a Certified Power BI Data Analyst and pass exam PL-300. Register now.

Reply
Pinarali
New Member

How to sum column if comparing specific row with another whole column

I have trouble with sum with condition. I do not have specific method needed, either power query or Dax is fine.

 

If Date1>=Date2 then sum QTY

But I want to compare Date1 each row with every row in column Date2, please see my sample data as below table. The calue I need is column "Need this value"

 

thank you very much in advance.

 

Date 1

Date 2

Qty

Need this value

How to calculate

1-Nov

2-Nov

2

0

1-Nov(Date1) is less than 2-Nov (Date2)and less than 4-Nov(Date2 in second row) and less than every Date in column Date2 then shows 0

1-Nov

4-Nov

1

0

Same with above

2-Nov

3-Nov

3

2

2-Nov(Date1) is = 2-Nov (Date2)then 2 and less than 4-Nov(Date2 in second row) then 0 and less than the rest Date in column Date2 then final result will be 2

3-Nov

4-Nov

4

5

3-Nov(Date1) is more than 2-Nov (Date2)then 2 and less than 4-Nov(Date2 in second row) then 0 and equals to 3-Nov(Date2 in third row) then 3 and less than the rest Date in column Date2 then final result will be 2+3 =5

4-Nov

5-Nov

2

10

4-Nov(Date1) is more than 2-Nov (Date2)then 2 and equals to 4-Nov(Date2 in second row) then 1 and more than 3-Nov(Date2 in third row) then 3 and equals to 4-Nov(Date2 in forth row) then 4 and less than the rest Date in column Date2 then final result will be 2+1+3+4=10

5-Nov

6-Nov

3

12

5-Nov(Date1) is more than 2-Nov (Date2)then 2 and equals to 4-Nov(Date2 in second row) then 1 and more than 3-Nov(Date2 in third row) then 3 and equals to 4-Nov(Date2 in forth row) then 4 and equals to 5-Nov (Date2 in fifth row) then 2, then final result will be 2+1+3+4+2 = 12

1 REPLY 1
tamerj1
Super User
Super User

Hi @Pinarali 

please try

Need this value =
VAR CurrentDate1 = 'Table'[Date1]
RETURN
    SUMX ( FILTER ( 'Table', 'Table'[Date2] <= CurrentDate1 ), 'Table'[Qty] ) + 0

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.