PowerBI filter- selected Date between Start and End date

久未见 提交于 2021-01-29 15:11:08

问题


I'm building a PowerBI report from a dataset that contains start and end dates. I'd like to filter the dataset based on rows that would encompass a selected date in another table.

The screenshot here shows a sample. I want to click a date in the table on the right and have the table on the left filtered where the selected date is between the start & end date.

I've attempted several different things using columns and measures, but I haven't been able to nail it down. I also attempted to create a new table from a DAX expression that references the selected date, but that caused errors.

How can I dynamically filter the dataset based on the selected date being between the start and end date values?


回答1:


Create a measure to check whether a row overlaps the selected date range:

Date Included = 
IF (
    FIRSTNONBLANK ( Table1[Start Date], 1 ) <= MAX ( 'Calendar'[Date] ) &&
    FIRSTNONBLANK( Table1[End Date], 1 ) >= MIN ( 'Calendar'[Date] ),
    "Include",
    "Exclude"
)

Add this Measure as a filter on your visualisation, where Date Included is Include

Now you can filter your Calendar table ( to single value, or range), and only overlapping rows from your fact table will be displayed.

See https://pwrbi.com/so_55925954/ for worked example PBIX file



来源:https://stackoverflow.com/questions/55925954/powerbi-filter-selected-date-between-start-and-end-date

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