Forum Discussion

sclement's avatar
sclement
Regular Visitor
4 years ago
Solved

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 p...
  • vojtechsima's avatar
    vojtechsima
    4 years ago

    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:

    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.

  • v-janeyg-msft's avatar
    v-janeyg-msft
    4 years ago

    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 )
    )

     

    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