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

Be one of the first to start using Fabric Databases. View on-demand sessions with database experts and the Microsoft product team to learn just how easy it is to get started. Watch now

Reply
Anonymous
Not applicable

Different result for date calculation using date slicer with or without hierarchy

Hi,
I've tried searching, but not seen this anywhere...
I'm building a report, and want to keep the date slicer small and simple, so I used a relative date slicer, which also updates to the current date, so that was nice. But when I then add a last year and last week measure, the result is that it will go back in time and show me the current day result. I found this to be linked to the slicer using date hierarchy or not.

Without hierarchy:

no hierarchy1.png

It seems the calculation goes back in time as requested, then shows the number for the selected date. 

 

With a hierarchy in the slicer:

with hierarchy.png

This is the result I was expecting, no matter if the hierarchy was added to the slicer.

 

Is there anyway to use the relative time slicer and still get the result as with the hierarchy?

 

Thanks

 

Øystein

1 ACCEPTED SOLUTION

Hi @Anonymous ,

If your date column is not continuously, not recommend to use Time-intelligence function like dateadd(), sameperiodlastyear() etc.

Based on your description, you can create a control measure like this, put it in the visual filter and set its value as 1:

Control = 
VAR _max =
    CALCULATE ( MAX ( 'Table'[Date] ), ALLSELECTED ( 'Table' ) )
VAR _min =
    CALCULATE ( MIN ( 'Table'[Date] ), ALLSELECTED ( 'Table' ) )
RETURN
    IF (
        SELECTEDVALUE ( 'Table'[Date] ) >= _min
            && SELECTEDVALUE ( 'Table'[Date] ) <= _max,
        1,
        0
    )

filter.png 

Then you can create measures like this:

now = SUM('Table'[value])
prev = 
CALCULATE (
    SUM ( 'Table'[value] ),
    FILTER (
        ALL ( 'Table' ),
        'Table'[Date]
            >= MIN ( 'Table'[Date] ) - 7
            && 'Table'[Date] <= MIN ( 'Table'[Date] )
    )
)
ly = 
CALCULATE (
    SUM ( 'Table'[value] ),
    FILTER (
        ALL ( 'Table' ),
        YEAR ( 'Table'[Date] )
            = YEAR ( MIN ( 'Table'[Date] ) ) - 1
            && QUARTER ( 'Table'[Date] ) = QUARTER ( MIN ( 'Table'[Date] ) )
            && MONTH ( 'Table'[Date] ) = MONTH ( MIN ( 'Table'[Date] ) )
            && DAY ( 'Table'[Date] ) = DAY ( MIN ( 'Table'[Date] ) )
    )
)

result.png

Attached a sample file in the below ,hopes to help you.

 

Best Regards,
Community Support Team _ Yingjie Li
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

 

View solution in original post

4 REPLIES 4
Anonymous
Not applicable

Hi,
Thanks for your reply. I'll check it out.

 

Øystein

Anonymous
Not applicable

Hi,
sorry, did not add the calculations:

appointment_counter_ly = CALCULATE(sum(sight_tests_details[appointment_counter]),SAMEPERIODLASTYEAR(sight_tests_details[appointment_date].[Date]))
 
appointment_prev7day = CALCULATE(sum(sight_tests_details[appointment_counter]),DATEADD(sight_tests_details[appointment_date].[Date], -7, DAY))
 
I don't think they're the problem, it's that they behave differently depending on the slicer...
 
Thanks for your reply.
 
Øystein

Hi @Anonymous ,

If your date column is not continuously, not recommend to use Time-intelligence function like dateadd(), sameperiodlastyear() etc.

Based on your description, you can create a control measure like this, put it in the visual filter and set its value as 1:

Control = 
VAR _max =
    CALCULATE ( MAX ( 'Table'[Date] ), ALLSELECTED ( 'Table' ) )
VAR _min =
    CALCULATE ( MIN ( 'Table'[Date] ), ALLSELECTED ( 'Table' ) )
RETURN
    IF (
        SELECTEDVALUE ( 'Table'[Date] ) >= _min
            && SELECTEDVALUE ( 'Table'[Date] ) <= _max,
        1,
        0
    )

filter.png 

Then you can create measures like this:

now = SUM('Table'[value])
prev = 
CALCULATE (
    SUM ( 'Table'[value] ),
    FILTER (
        ALL ( 'Table' ),
        'Table'[Date]
            >= MIN ( 'Table'[Date] ) - 7
            && 'Table'[Date] <= MIN ( 'Table'[Date] )
    )
)
ly = 
CALCULATE (
    SUM ( 'Table'[value] ),
    FILTER (
        ALL ( 'Table' ),
        YEAR ( 'Table'[Date] )
            = YEAR ( MIN ( 'Table'[Date] ) ) - 1
            && QUARTER ( 'Table'[Date] ) = QUARTER ( MIN ( 'Table'[Date] ) )
            && MONTH ( 'Table'[Date] ) = MONTH ( MIN ( 'Table'[Date] ) )
            && DAY ( 'Table'[Date] ) = DAY ( MIN ( 'Table'[Date] ) )
    )
)

result.png

Attached a sample file in the below ,hopes to help you.

 

Best Regards,
Community Support Team _ Yingjie Li
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

 

amitchandak
Super User
Super User

@Anonymous , how you created these measures.  Please share formula.

refer these , if they can help

Power BI — Year on Year with or Without Time Intelligence
https://medium.com/@amitchandak.1978/power-bi-ytd-questions-time-intelligence-1-5-e3174b39f38a

 

Power BI — Week on Week and WTD
https://medium.com/@amitchandak.1978/power-bi-wtd-questions-time-intelligence-4-5-98c30fab69d3
https://community.powerbi.com/t5/Community-Blog/Week-Is-Not-So-Weak-WTD-Last-WTD-and-This-Week-vs-Last-Week/ba-p/1051123

Join us as experts from around the world come together to shape the future of data and AI!
At the Microsoft Analytics Community Conference, global leaders and influential voices are stepping up to share their knowledge and help you master the latest in Microsoft Fabric, Copilot, and Purview.
️ November 12th-14th, 2024
 Online Event
Register Here

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

ArunFabCon

Microsoft Fabric Community Conference 2025

Arun Ulag shares exciting details about the Microsoft Fabric Conference 2025, which will be held in Las Vegas, NV.

December 2024

A Year in Review - December 2024

Find out what content was popular in the Fabric community during 2024.