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

Vote for your favorite vizzies from the Power BI Dataviz World Championship submissions. Vote now!

Reply
Anonymous
Not applicable

Calculating number of days between two dates

Hi.


I have an Invoice table with Invoice_Startdt, Invoice_Enddt and Amount.
The period of this amounts can be from days to thre or four months.


What I want to do in a measure is:
Find how many days there is between the dates (Startdt - Enddt)

Divide the Amount from Amount on the number of days betweeen the dates.

 

Ex:
Start_dt: 01.01.2017

End_dt: 30.01.2017

Amount: 499

 

Days between dates: 30

499 / 30 = 16,63

 

So I want a measure who find 16,63

 

Best regards

Marius

1 ACCEPTED SOLUTION
Anonymous
Not applicable

Here is a Solution in Power Query, which adds a new column in the table:

    #"Inserted Age" = Table.AddColumn(#"Changed Type", "Duration", each 1 + Number.From([End_dt] - [Start_dt]), type number),
    #"Added Custom" = Table.AddColumn(#"Inserted Age", "Custom", each [Amount]/[Duration])

The first line calculates the difference in days. The second divides the amount per line by the number of days.

 

DAX Solution (Measure):

DAX_Measure = 
DIVIDE(sum(Tabelle1[Amount]);
(DATEDIFF(min(Tabelle1[Start_dt]);MAX(Tabelle1[End_dt]);DAY)+1))

But I don't think, that the DAX measure is the way to go, as your calculation is just semi-additive. Up to you which one works for your case.

Hope this helps.

 

View solution in original post

4 REPLIES 4
Anonymous
Not applicable

Hi @Anonymous

Do you need an extra column in your table per row or a measure?

Anonymous
Not applicable

Hi @Anonymous


Thanks for your reply.


I think I only need a measure, but would it be to much if you comes with a suggestion on both?

That would be great.

 

Best regards
Marius

Anonymous
Not applicable

Here is a Solution in Power Query, which adds a new column in the table:

    #"Inserted Age" = Table.AddColumn(#"Changed Type", "Duration", each 1 + Number.From([End_dt] - [Start_dt]), type number),
    #"Added Custom" = Table.AddColumn(#"Inserted Age", "Custom", each [Amount]/[Duration])

The first line calculates the difference in days. The second divides the amount per line by the number of days.

 

DAX Solution (Measure):

DAX_Measure = 
DIVIDE(sum(Tabelle1[Amount]);
(DATEDIFF(min(Tabelle1[Start_dt]);MAX(Tabelle1[End_dt]);DAY)+1))

But I don't think, that the DAX measure is the way to go, as your calculation is just semi-additive. Up to you which one works for your case.

Hope this helps.

 

Anonymous
Not applicable

@Anonymous Thank you so much for your time!
The new columns workd fine, just what I wanted!

 

Have a nice day 🙂

Best regards
Marius

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

Vote for your favorite vizzies from the Power BI World Championship submissions!

Sticker Challenge 2026 Carousel

Join our Community Sticker Challenge 2026

If you love stickers, then you will definitely want to check out our Community Sticker Challenge!

January Power BI Update Carousel

Power BI Monthly Update - January 2026

Check out the January 2026 Power BI update to learn about new features.

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.