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

Grow your Fabric skills and prepare for the DP-600 certification exam by completing the latest Microsoft Fabric challenge.

Reply
JDC1993
New Member

Date table hierarchy not filtering dates properly

I've searched and searched to find a post with a similar issue, but I'm at a loss. Apologies if this has been answered before. 

 

I'm currently facing an issue where my date table hierarchy will not properly filter rows in a slicer, especially when used with ALLSELECTED in a measure. I know the hierarchy is to blame (at least partly), because everything works as it should when I use the 'Date'[Date] column in the slicer as opposed to the hierarchy. My date table is set up with a relationship to the main fact table bi-directionally and with many-to-one cardinality. My auto time intelligence is turned off.

 

Here is the measure I'm trying to get working:

 

Monthly Total Cost Variance (%) =
VAR CurrentMonthTotal =
    CALCULATE (
        SUM ( Analytics[Total Cost ($)] ),
        LASTDATE ( ALLSELECTED ( 'Date'[Date] ) ),
        ALLEXCEPT ( Analytics, Analytics[Account Number] )
    )
VAR PastMonthTotal =
    CALCULATE (
        SUM ( Analytics[Total Cost ($)] ),
        DATEADD ( LASTDATE ( ALLSELECTED ( 'Date'[Date] ) )-1MONTH ),
        ALLEXCEPT ( Analytics, Analytics[Account Number] )
    )
RETURN
    DIVIDE ( CurrentMonthTotal - PastMonthTotalPastMonthTotalBLANK () )

 

 

 

The desired behaviour is to have the measure display the variance for the most recent (filtered) month. If 'All' is selected in the slicer, it should display variances only for the most recent month, but with the hierarchy, it's will only display the most recent month, even if a month from the previous year is selected in the slicer. As I said, if I put the 'Date'[Date] column in the slicer instead, everything works as expected, so it has to be something with the way the hierarchy is constructed. 

 

Any help is greatly appreciated!

1 REPLY 1
v-yiruan-msft
Community Support
Community Support

Hi @JDC1993 ,

Could you please provide the related screenshots(mask the sensitive data) with visual settings(include Fields pane) and mark the wrong data with some explanation in order to make troubleshooting? Which field is applying on the slicer currently? It is from the date field of table Analytics? Thank you.

In addition, you can refer the content in the following blogs to get it.

Comparison- current month vs previous month

Current Month , Previous Month and Before Previous Month

How to use Date vs Date Hierarchy in Power BI

Best Regards

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

Helpful resources

Announcements
RTI Forums Carousel3

New forum boards available in Real-Time Intelligence.

Ask questions in Eventhouse and KQL, Eventstream, and Reflex.

MayPowerBICarousel1

Power BI Monthly Update - May 2024

Check out the May 2024 Power BI update to learn about new features.