Filter Recent date in filter

你说的曾经没有我的故事 提交于 2020-04-18 06:46:46

问题


I want the Slicer in Power BI to select the most recent date of the selection to be selected automatically.

Here is an example of the drop down:

https://i.imgur.com/IykHSlI.png

This drop down differs from the Client selection.


回答1:


I solved this issue the following way:

  • I created one Report with a filter to Default_Date (which opens first)
  • I used a Calculated Column [Default_Date] to populate the filter (which is hidden)
  • In my case the user wanted to see Yesterday's data as the default date so I selected 'Yesterday' on my filter.
  • Then I put a button that opens another duplicated copy of the Report [Hidden Tab] that contains a full calendar filter, so the user can select any other dates he likes, this hidden report has another button that returns the user to the main report [if he wants to].

picture of my filter (which I collapse and hide under a color box/banner)

Here is the formula for the calculated column (used in the filter):

    Default_Date = 
VAR TodaysDate =
    TODAY()
VAR YesterdayDate =
    TODAY() - 1
VAR reportDate =
    SWITCH(TRUE(),
        'Calendar'[Date] = TodaysDate, "Today",
        'Calendar'[Date] = YesterdayDate, "Yesterday", 
        "Before Yesterday"
    )
RETURN
    reportDate

Use Default_Date in your filter, and you can replace TODAY() with

CALCULATE(Max(Table[Date]),All(Table))

and remove what you don't need.

If you want to get the Last Date of selected items, then

CALCULATE(Max(Table[Date]),ALLSELECTED(Table))

Table may need to be in quotes to work: 'Table'[Date]

I hope this helps.




回答2:


There isn't to set a default value in Power BI, but there are a few around about ways. First you can try Persistent Filters that can preserve the filters selected. The other option, is to create in your data set, if you have a calendar table, or are able to add it to your column a current date flag, that you can apply as a filter to your report.

For example you can use the TODAY() to return todays date, and check against your date column.

Calculated column = IF(MONTH(TODAY()) = MONTH('table'[DateColumn]) && YEAR(TODAY()) = YEAR('table'[DateColumn]), "Y", "N")

You can run the report and it will always filter on the latest date, however you will have to remove the filter if you want to see other dates. You could set up bookmarks so that you can easily add/remove filter to the report. So you would have one bookmark with latest date, and the other to remove it. You can allow the slicer box to appear when you select the 'remove current month' bookmark

Hope that helps



来源:https://stackoverflow.com/questions/58602466/filter-recent-date-in-filter

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!