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
amandabus21
Helper V
Helper V

Days Between Summed Up

Hello,

 

I have a calculated column where I calcualte the Days between the Max Delivery Date per Purchase Order.

 

CALCULATE(
    DATEDIFF(
        MAX('Purchase Orders'[Delivery Date.Delivery Date Level 01]),
        TODAY(),
        DAY
    ),
    ALLEXCEPT(
        'Purchase Orders',
        'Purchase Orders'[Purchase Order #.Purchase Order # Level 01]
    )
)
 
 

It works fine but when I click "Sum" for the visualization, it starts adding up all the Days Between instead of just summing up the max days between.

 

 

basically in the screen shot, i want it to sum the top left correttly. When i click sumn, the top right is what happens and is incorrect. 

 

The bottom is an example of each purchase order with the delivery date and days between compared to the current Date.

 

amandabus21_0-1689271293428.png

 

 

 

 

6 REPLIES 6
amandabus21
Helper V
Helper V

That one did not work. Additonally I need a column becuase I need to run IF statements around it.

@amandabus21 
Max Days Between =
VAR CurrentOrder = 'Purchase Orders'[Purchase Order #.Purchase Order # Level 01]
VAR CurrentDeliveryDate = 'Purchase Orders'[Delivery Date.Delivery Date Level 01]
VAR MaxDeliveryDate = CALCULATE(MAX('Purchase Orders'[Delivery Date.Delivery Date Level 01]), ALLEXCEPT('Purchase Orders', 'Purchase Orders'[Purchase Order #.Purchase Order # Level 01]))
RETURN
IF(CurrentDeliveryDate = MaxDeliveryDate, DATEDIFF(MaxDeliveryDate, TODAY(), DAY), BLANK())

BBF

Still not working. 

 

For example for PO 4500055313 its saying the Sum of Days Between is -108 from 7/26/2023. When it should be -12 Days.

 

amandabus21_0-1689360513781.png

 

BeaBF
Super User
Super User

Hi @amandabus21 ,

try with sumx:

Max Days Between =
VAR MaxDeliveryDate = MAX('Purchase Orders'[Delivery Date.Delivery Date Level 01])
RETURN
SUMX (
VALUES('Purchase Orders'[Purchase Order #.Purchase Order # Level 01]),
CALCULATE (
DATEDIFF (
MaxDeliveryDate,
TODAY(),
DAY
)
)
)

By using Sumx you ensure that only the maximum value for each purchase order is summed up when you apply the sum aggregation in the visual


BBF

This kind of works as a measure except is not totaling correctly. When i dump in excel the correct sum is -14,073.

 

amandabus21_0-1689278335588.png

 

 

Also is there a way for it to work as a calc column?

@amandabus21  Try with:
Max Days Between =
VAR MaxDeliveryDate = MAX('Purchase Orders'[Delivery Date.Delivery Date Level 01])
RETURN
IF('Purchase Orders'[Delivery Date.Delivery Date Level 01] = MaxDeliveryDate,
DATEDIFF(MaxDeliveryDate, TODAY(), DAY),
BLANK()
)

BBF

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.