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
ImNewUser
Regular Visitor

How to show next 2 days of selected date?

Hi All, 

 

I'm new to Power BI and I am having difficulties. I have some slicers as filters and two chart as below:

Untitled.png

 

The bottom chart shows data with data according to date selected in the slicers which is straight forward. E.g. The slicer selected 15-Oct-2017, the bottom chart should shows 15-Oct-2017 as well.

 

The upper chart should shows the next 2 days of the selected chart, i.e. data of 16&17-Oct-2017 should be shown. How do I achieve this in a dynamic way so that when slicer selection change, this chart changes accordingly?

 

Thanks in advance

 

1 ACCEPTED SOLUTION

Hi @ImNewUser,

I test using your sample data and get expected result. Please follow the steps below.

1. Create a Calendar table. Create Calculated columns the Year, Month, Day, and the next to days using the formula below.

Year = YEAR('Calendar'[Date])
Month = MONTH('Calendar'[Date])
Day = DAY('Calendar'[Date])
next 2 days = 'Calendar'[Date]+2


2. Create three slicers including Calendar[Year], Calendar[Month], Calendar[Day] separately. 

3. Create two measures to get the filtered data and corresponding next two day.

Selected value = SELECTEDVALUE('Calendar'[Date])
next 2 days selected = SELECTEDVALUE('Calendar'[next 2 days])


4. Create a slicer including Table[Area], create two measure to get count value the next two days  and selected date as follows.

next 2 days value11 =
CALCULATE (
    SUM ( Table1[Count] ),
    FILTER (
        Table1,
        AND (
            DATE ( YEAR ( Table1[Starting Date] ), MONTH ( Table1[Starting Date] ), DAY ( Table1[Starting Date] ) )
                > [Selected value],
            DATE ( YEAR ( Table1[Starting Date] ), MONTH ( Table1[Starting Date] ), DAY ( Table1[Starting Date] ) )
                <= [next 2 days selected]
        )
    )
)


filtered date =
CALCULATE (
    SUM ( Table1[Count] ),
    FILTER (
        Table1,
        DATE ( YEAR ( Table1[Starting Date] ), MONTH ( Table1[Starting Date] ), DAY ( Table1[Starting Date] ) )
            = [Selected value]
    )
)


Please review the expected result as the screenshot shown.

1.PNG

You can download the .pbix file from attachment for more details.

Best Regards,
Angelia

View solution in original post

5 REPLIES 5
v-huizhn-msft
Employee
Employee

Hi @ImNewUser,

What your data source look like? You have one or two tables? You'd better share your sample table, you can create a fake one if your data is private, so that we can help you in dedicatedly.

Thanks,
Angelia

Hi Angelia,

 

Thanks for helping. This is my first time to post a thread and i'm not sure how to attach file to here... Anyway, the data is fake and is simple, I'm pasting as below:

Record NumberStarting DateAreaCount
115/10/2017 13:00:00A12
215/10/2017 14:00:00A13
315/10/2017 15:00:00A14
415/10/2017 16:00:00A15
515/10/2017 20:00:00A16
615/10/2017 07:00:00A17
716/10/2017 09:00:00A18
816/10/2017 12:00:00A19
916/10/2017 18:00:00A20
1016/10/2017 22:00:00A21
1117/10/2017 10:00:00A22
1217/10/2017 16:00:00A23
1317/10/2017 19:00:00A24
1415/10/2017 13:00:00B25
1515/10/2017 14:00:00B26
1615/10/2017 15:00:00B27
1715/10/2017 16:00:00B28
1815/10/2017 20:00:00B29
1915/10/2017 07:00:00B30
2016/10/2017 09:00:00B31
2116/10/2017 12:00:00B32
2216/10/2017 18:00:00B33
2316/10/2017 22:00:00B34
2417/10/2017 10:00:00B35
2517/10/2017 16:00:00B36
2617/10/2017 19:00:00B37

Hi @ImNewUser,

I test using your sample data and get expected result. Please follow the steps below.

1. Create a Calendar table. Create Calculated columns the Year, Month, Day, and the next to days using the formula below.

Year = YEAR('Calendar'[Date])
Month = MONTH('Calendar'[Date])
Day = DAY('Calendar'[Date])
next 2 days = 'Calendar'[Date]+2


2. Create three slicers including Calendar[Year], Calendar[Month], Calendar[Day] separately. 

3. Create two measures to get the filtered data and corresponding next two day.

Selected value = SELECTEDVALUE('Calendar'[Date])
next 2 days selected = SELECTEDVALUE('Calendar'[next 2 days])


4. Create a slicer including Table[Area], create two measure to get count value the next two days  and selected date as follows.

next 2 days value11 =
CALCULATE (
    SUM ( Table1[Count] ),
    FILTER (
        Table1,
        AND (
            DATE ( YEAR ( Table1[Starting Date] ), MONTH ( Table1[Starting Date] ), DAY ( Table1[Starting Date] ) )
                > [Selected value],
            DATE ( YEAR ( Table1[Starting Date] ), MONTH ( Table1[Starting Date] ), DAY ( Table1[Starting Date] ) )
                <= [next 2 days selected]
        )
    )
)


filtered date =
CALCULATE (
    SUM ( Table1[Count] ),
    FILTER (
        Table1,
        DATE ( YEAR ( Table1[Starting Date] ), MONTH ( Table1[Starting Date] ), DAY ( Table1[Starting Date] ) )
            = [Selected value]
    )
)


Please review the expected result as the screenshot shown.

1.PNG

You can download the .pbix file from attachment for more details.

Best Regards,
Angelia

How did you get starting date in table.

 

I have the similar type of doubt but i did not get the result....


@v-huizhn-msft wrote:

Hi @ImNewUser,

I test using your sample data and get expected result. Please follow the steps below.

1. Create a Calendar table. Create Calculated columns the Year, Month, Day, and the next to days using the formula below.

Year = YEAR('Calendar'[Date])
Month = MONTH('Calendar'[Date])
Day = DAY('Calendar'[Date])
next 2 days = 'Calendar'[Date]+2


2. Create three slicers including Calendar[Year], Calendar[Month], Calendar[Day] separately. 

3. Create two measures to get the filtered data and corresponding next two day.

Selected value = SELECTEDVALUE('Calendar'[Date])
next 2 days selected = SELECTEDVALUE('Calendar'[next 2 days])


4. Create a slicer including Table[Area], create two measure to get count value the next two days  and selected date as follows.

next 2 days value11 =
CALCULATE (
    SUM ( Table1[Count] ),
    FILTER (
        Table1,
        AND (
            DATE ( YEAR ( Table1[Starting Date] ), MONTH ( Table1[Starting Date] ), DAY ( Table1[Starting Date] ) )
                > [Selected value],
            DATE ( YEAR ( Table1[Starting Date] ), MONTH ( Table1[Starting Date] ), DAY ( Table1[Starting Date] ) )
                <= [next 2 days selected]
        )
    )
)


filtered date =
CALCULATE (
    SUM ( Table1[Count] ),
    FILTER (
        Table1,
        DATE ( YEAR ( Table1[Starting Date] ), MONTH ( Table1[Starting Date] ), DAY ( Table1[Starting Date] ) )
            = [Selected value]
    )
)


Please review the expected result as the screenshot shown.

1.PNG

You can download the .pbix file from attachment for more details.

Best Regards,
Angelia


 

Hi @v-huizhn-msft,

 

Thanks for the help, it does solve my problem!

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.