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

Get Fabric Certified for FREE during Fabric Data Days. Don't miss your chance! Learn more

Reply
Anonymous
Not applicable

Calculate number of days between today's date and previous date

I have a policy effective date in my dataset.

I need to calculate the number of days from that date, to today. And I want to do this in Query Editor, not Dax.

 

I used the following formula which doesn't work, see screenshot. Changing the column type also doesn't seem to make a difference

 

= Table.AddColumn(PreviousStep, "Days since EffectiveDate", each (DateTime.LocalNow()-[EffectiveDate]))

 

Sample.PNG

1 ACCEPTED SOLUTION
Greg_Deckler
Community Champion
Community Champion

Hmm, try this:

 

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("ddFBCoQwDIXhqwxZC21SrXZ2uplDlJ5hRPD+zqID5dfuCl+SkrycxZypM6/p5d/eyyCf43vu6++hUobWFW5wgwd4gI/wET7BJ3iER/j893Cfv7X7hfv8rd3vwdeHfv7P/rl3n+pL7z7VU+8+1ZUBRhYwQV5IGeHCAmaYpJQL", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type text) meta [Serialized.Text = true]) in type table [Timestamp = _t, Group = _t, RunningTotal = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Timestamp", type datetime}, {"Group", type text}, {"RunningTotal", Int64.Type}}),
    #"Added Custom" = Table.AddColumn(#"Changed Type", "Custom", each DateTime.LocalNow() - [Timestamp])
in
    #"Added Custom"

Perhaps the issue is your time is a Date and not a Date Time?



Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
DAX For Humans

DAX is easy, CALCULATE makes DAX hard...

View solution in original post

3 REPLIES 3
Greg_Deckler
Community Champion
Community Champion

Yeah, that's really strange, shouldn't be any different putting it into a formula versus a separate column. Weird!



Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
DAX For Humans

DAX is easy, CALCULATE makes DAX hard...
Greg_Deckler
Community Champion
Community Champion

Hmm, try this:

 

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("ddFBCoQwDIXhqwxZC21SrXZ2uplDlJ5hRPD+zqID5dfuCl+SkrycxZypM6/p5d/eyyCf43vu6++hUobWFW5wgwd4gI/wET7BJ3iER/j893Cfv7X7hfv8rd3vwdeHfv7P/rl3n+pL7z7VU+8+1ZUBRhYwQV5IGeHCAmaYpJQL", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type text) meta [Serialized.Text = true]) in type table [Timestamp = _t, Group = _t, RunningTotal = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Timestamp", type datetime}, {"Group", type text}, {"RunningTotal", Int64.Type}}),
    #"Added Custom" = Table.AddColumn(#"Changed Type", "Custom", each DateTime.LocalNow() - [Timestamp])
in
    #"Added Custom"

Perhaps the issue is your time is a Date and not a Date Time?



Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
DAX For Humans

DAX is easy, CALCULATE makes DAX hard...
Anonymous
Not applicable

@Greg_Deckler good point, so I tried changing [EffectiveDate] to DateTime and it made the formula even worse! 

 

To get around this I have created a [Today] column, and then highlighted both columns > Add Column > Date > Subtract
This got me my value. I wanted to embed the [Today] in one formula though rather than create a separate column. In excel it is literally 

=Sum(Today() - [@EffectiveDate])

 

Anyway, thank you for your suggested solution but I think mine is a little simpler (you might say cruder!)

 

Jemma

Helpful resources

Announcements
Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

October Power BI Update Carousel

Power BI Monthly Update - October 2025

Check out the October 2025 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.

Top Solution Authors