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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
sclement
Regular Visitor

PowerBI Date Manipulation

Hi All,

 

I am currently generating a report about purchase details on daily basis. I would like to get yesterday's purchase details till today 5 PM and after 5 PM, the report should show today's purchase details. 

 

Is there a way to implement this in PowerBI report?

 

Thanks in advance!

2 ACCEPTED SOLUTIONS

Hi, @sclement 
There is a NOW() function, that returns the current day and time.
If it's a measure, the time is refreshed upon refreshing the page (when published).
If it's a calculated column, the time is refreshed only upon refreshing the whole report.

I designed a measure and calculated column that would fit your needs:
Measure:

 

NowMeasure = 
var currentDay = TODAY()
var previousDay_ = currentDay-1

var CurrentDayFromTable = MAXX(FILTER(DatetimeAmount, DatetimeAmount[Date] = currentDay), DatetimeAmount[Date])
var PreviousDayFromTable = MAXX(FILTER(DatetimeAmount, DatetimeAmount[Date] = previousDay_), DatetimeAmount[Date])

var check = IF(DATEVALUE(NOW()) = currentDay && HOUR(NOW()) <= 16 && MINUTE(NOW())<=59, PreviousDayFromTable, CurrentDayFromTable)
return check

 

Column:

 

Column = 
var CurrentRowDate = DatetimeAmount[Date]
return IF([NowMeasure]=CurrentRowDate, 1, 0)

 

 It works as you described it:

vojtechsima_0-1649863059230.png

The only drawback is that you would have to refresh your repot at 5 PM and then 12AM the next day.
So far I couldn'T come up with a better solution.

EDIT: 
You also have to then put a filter to your visualization and display only rows that equal 1.

View solution in original post

Hi, @sclement 

 

According to your description, I think you can create a meaure and use it in visual filter pane to filter data.

Like this:

Measure 2 = 
IF (
    DATEVALUE ( NOW () ) = TODAY ()
        && HOUR ( NOW () ) <= 16
        && MINUTE ( NOW () ) <= 59,
    IF ( SELECTEDVALUE('Table'[Date]) = TODAY () ||SELECTEDVALUE('Table'[Date]) = TODAY () - 1, 1 ),
    IF ( SELECTEDVALUE('Table'[Date]) = TODAY (), 1 )
)

vjaneygmsft_1-1650279997874.png

 

vjaneygmsft_2-1650280022015.png

Did I answer your question? Please mark my reply as solution. Thank you very much.
If not, please feel free to ask me.

Best Regards,
Community Support Team _ Janey

View solution in original post

5 REPLIES 5
sclement
Regular Visitor

Hi @vojtechsima ,

 

Sorry for the confusion.

 

I am using a matrix visualzation in the report and currently my visualization shows similar data as follows:

Screen Shot 2022-04-13 at 11.07.38 pm.pngBut I would like to have visualization to show below data when I am looking at the report before 5 PM on 13th April 2022.

Screen Shot 2022-04-13 at 11.07.47 pm.png

 and If I am looking at the report after 5 PM on 13th April 2022, the report should display as follows:

Screen Shot 2022-04-13 at 11.07.52 pm.png

I am not sure whether this has to be implemented with a measure or in power query. So please help.

 

Thank you for the heads up! 

 

Hi, @sclement 
There is a NOW() function, that returns the current day and time.
If it's a measure, the time is refreshed upon refreshing the page (when published).
If it's a calculated column, the time is refreshed only upon refreshing the whole report.

I designed a measure and calculated column that would fit your needs:
Measure:

 

NowMeasure = 
var currentDay = TODAY()
var previousDay_ = currentDay-1

var CurrentDayFromTable = MAXX(FILTER(DatetimeAmount, DatetimeAmount[Date] = currentDay), DatetimeAmount[Date])
var PreviousDayFromTable = MAXX(FILTER(DatetimeAmount, DatetimeAmount[Date] = previousDay_), DatetimeAmount[Date])

var check = IF(DATEVALUE(NOW()) = currentDay && HOUR(NOW()) <= 16 && MINUTE(NOW())<=59, PreviousDayFromTable, CurrentDayFromTable)
return check

 

Column:

 

Column = 
var CurrentRowDate = DatetimeAmount[Date]
return IF([NowMeasure]=CurrentRowDate, 1, 0)

 

 It works as you described it:

vojtechsima_0-1649863059230.png

The only drawback is that you would have to refresh your repot at 5 PM and then 12AM the next day.
So far I couldn'T come up with a better solution.

EDIT: 
You also have to then put a filter to your visualization and display only rows that equal 1.

That's a great solution @vojtechsima. Thank you very much for sharing this with me.

 

Since I am using Direct query to fetch the data from database (this is because I have large dataset in our company's database) into visualisation, I have difficulities with this DAX functions that you have used in the measure. Do you think perhaps I can implement similar approach for direct query data fetching as well?

 

PS: Apologies for asking too many questions as I am a newbie to this area in PowerBi. 

 

Thank you!

Hi, @sclement 

 

According to your description, I think you can create a meaure and use it in visual filter pane to filter data.

Like this:

Measure 2 = 
IF (
    DATEVALUE ( NOW () ) = TODAY ()
        && HOUR ( NOW () ) <= 16
        && MINUTE ( NOW () ) <= 59,
    IF ( SELECTEDVALUE('Table'[Date]) = TODAY () ||SELECTEDVALUE('Table'[Date]) = TODAY () - 1, 1 ),
    IF ( SELECTEDVALUE('Table'[Date]) = TODAY (), 1 )
)

vjaneygmsft_1-1650279997874.png

 

vjaneygmsft_2-1650280022015.png

Did I answer your question? Please mark my reply as solution. Thank you very much.
If not, please feel free to ask me.

Best Regards,
Community Support Team _ Janey

vojtechsima
Memorable Member
Memorable Member

Hi, @sclement 
It's definitely possible, I just wonder about the result, could you please share a snippet of your desired output?
Should it be two measures?
One that shows today's till 5PM and second about yesterday's (whole day). 
Your initial request confuses me a bit. Thank you

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.