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

Be one of the first to start using Fabric Databases. View on-demand sessions with database experts and the Microsoft product team to learn just how easy it is to get started. Watch now

Reply
Anonymous
Not applicable

Column to Find days between dates

Hello, I am looking at traffic on a webpage and for a each page, i have a different publish date. I would like to see the number of days since the publish date for each pageview in a new column. 

 

I tried this but i cant seem to get it to work:

 

if([Date]>=DATE(2019,6,7) && ([Date]<DATE(2019,6,21))DATE(2019,6,7), DATE(2019,6,21))

1 ACCEPTED SOLUTION

That is the PowerQuery editor which uses an entirely different language, called M.  Your formula will look something like this.

= if [Date] >= Date.FromText("6/7/2019") and [Date] < Date.FromText("6/21/2019") then Date.FromText("6/7/2019") else Date.FromText("6/21/2019")

I would load it to PowerBI and do it in DAX rather than adding the column in the query editor.

View solution in original post

5 REPLIES 5
MitchM
Resolver II
Resolver II

Two things, from a dax perspective you are missing a comma. The DAX below is fixed. Also, is [Date] a column or measure? Do you want your output to be a calculated column or measure? This should help direct a better answer should the missing comma not be the problem.

Test = 
IF(
    [Date] >=DATE(2019,6,7) && 
    ( [Date]<DATE(2019,6,21)),
    DATE(2019,6,7),
    DATE(2019,6,21))
Anonymous
Not applicable

Hi @MitchM

 

I am looking to produce a calculated column.

 

I tried your code but i recivere a "Token Literal Expected" Error

 

Code.PNG

That is the PowerQuery editor which uses an entirely different language, called M.  Your formula will look something like this.

= if [Date] >= Date.FromText("6/7/2019") and [Date] < Date.FromText("6/21/2019") then Date.FromText("6/7/2019") else Date.FromText("6/21/2019")

I would load it to PowerBI and do it in DAX rather than adding the column in the query editor.

jdbuchanan71
Super User
Super User

Hello @Anonymous ,

Can you give us a screen shot of the table layout?  If you have two columns of dates in a single table [Publish Date] and [Traffic Date] you can just do [Traffic Date] - [Publish Date] in a new column to get the number of days.

Anonymous
Not applicable

Capture.PNG

 

Yes that would work, but i suppose what i am trying to do is match a view date to a publish date. in pseudo code;

 

If the "Date" is >= June 7 && < June 21, then the"publish date"is June 7th else, publish date is June 21

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!

Dec Fabric Community Survey

We want your feedback!

Your insights matter. That’s why we created a quick survey to learn about your experience finding answers to technical questions.

ArunFabCon

Microsoft Fabric Community Conference 2025

Arun Ulag shares exciting details about the Microsoft Fabric Conference 2025, which will be held in Las Vegas, NV.

December 2024

A Year in Review - December 2024

Find out what content was popular in the Fabric community during 2024.