cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Asma Frequent Visitor
Frequent Visitor

Relative Day DAX

Hello everyone, I need to create a column in a date table that show the relative day Number 

for exemple if the date of Today is 09/03/2017

If the day chosen is 09/03/2017 than Relative day Number = 0 

if the day chosen is 10/03/2017 than Relative day Number = 1

if the day chosen is 08/10/2017 than Relative day Number = -1

 

I already calculate the Relative Year Number = 'Dates'[Year]-YEAR(Now())

the Relative Month Number = 'Dates'[Month]-MONTH(Now()) + 12* 'Dates'[Relative Year Number]

and the Relative Quarter Number = 'Dates'[QuarterofYear]-MONTH(NOW()+2/3)+ 4* 'Dates'[Relative Year Number] and it's working.

Now I am trying to Calculate the Relative Day Number using the same methode  however - I can't figure out a way to count the number of days for each year and can't found a function that returns the number of Today of year ( a number from 1 to Number of days in the year)

 

Is there a way to create this in Power BI - using DAX (which I'm not familar with at all)

 

 

Any ideas, suggestions or points in the right direction - would be greatly appreciated! Smiley Happy 

 

Thanks!

1 ACCEPTED SOLUTION

Accepted Solutions
Highlighted
Asma Frequent Visitor
Frequent Visitor

Re: Relative Day DAX

@v-huizhn-msft Well I found the solution, here it is 🙂 

 

Relative Day Number = IF('Dates'[Date]> TODAY();(DATEDIFF(TODAY();'Dates'[Date]; DAY ));-1 *(DATEDIFF('Dates'[Date];TODAY(); DAY )))

Thank you for your help

View solution in original post

3 REPLIES 3
Microsoft v-huizhn-msft
Microsoft

Re: Relative Day DAX

Hi @Asma,

Please try create a calculated column using the formula.

Relative day Number=IF(Dates[Date]=NOW(),0,IF(Dates[Date]>NOW(),1,-1))


If this doesn't resolve your issue, please share your sample data for further analysis.

Best Regards,
Angelia

Asma Frequent Visitor
Frequent Visitor

Re: Relative Day DAX

@v-huizhn-msft Hi Angelia, thank you for your help but unfortunately your solution didn't work for me for the sample reason that my data has many years, and I want the relative Day number to be counted for any day of any year... Not only for the previous and the next days.

for exemple if the date of Today is 09/03/2017 and the day chosen is 09/03/2016 than Relative day Number = -365 .... and so on....

here a part of my database DAY.PNG

 

 

 

Best Regards,

Asma

Highlighted
Asma Frequent Visitor
Frequent Visitor

Re: Relative Day DAX

@v-huizhn-msft Well I found the solution, here it is 🙂 

 

Relative Day Number = IF('Dates'[Date]> TODAY();(DATEDIFF(TODAY();'Dates'[Date]; DAY ));-1 *(DATEDIFF('Dates'[Date];TODAY(); DAY )))

Thank you for your help

View solution in original post

Helpful resources

Announcements
Coming Soon: T-Shirt Design Contest

Coming Soon: T-Shirt Design Contest

Keep your eyes open for our upcoming T-shirt design contest!

Meet the 2020 Season 1 Power BI Super Users!

Meet the 2020 Season 1 Power BI Super Users!

It’s the start of a new Super User season! Learn all about the new Super Users and brand-new tiered recognition system.

Super User Challenge: Can You Solve These?

Super User Challenge: Can You Solve These?

We're celebrating the start of the New Super User season with our first ever Super User 'Can You Solve These?' challenge.

Power BI Desktop Update - February 2020

Power BI Desktop Update - February 2020

We are super excited for our update this month, as we are releasing two of our top community requests!

Power Platform Online Conference

Power Platform Online Conference

Join us for the first ever Power Platform Online Conference!

Top Solution Authors
Top Kudoed Authors