Search code examples
daxpowerbi-desktoppower-bi-report-server

How to filter dates before or equal a selected value in a segment w/o using date slicer in PowerBI


I have a visual in PowerBI showing values by quarter and I want to show only the quarter that are before or equal to the selected date in a segment, how to do that ?

When I use the segment the interaction on the other visuals filter only on the equal selection. I want the dates filtered before or equal the selection. I don't want to use the date silder because I want the selection to be only by quarter and not on a specific date.

Below is a screenshot of what I'm looking for :

(i) it shows the current behavior based on the selection

(ii) it shows what I would like to do

see what I expected to do

This is my model (I have two data tables related to one date table)

see my model

I tried this query but it doesn't work

Total Numbers =
CALCULATE(
    SUM('T_Data_1'[Numbers]),
    FILTER(
        T_Data_1,
        T_Data_1[Date] <= MAX(T_Dates[TrimestreDate])
    )
)

I also tried Dynamic Parameter M but I'm not using Direct Query so I wasn't able to bind the paramater and my report will be published on PowerBI Report Server that doesn't support the feature.


Solution

  • Someone found the solution from another forum so I share it here:

    It requires to create an additional date table independant from the others. I created this independant table based on the first date table so I have the same threashold:

    T_Dates_Ind = GENERATE (
            DISTINCT(T_Dates[TrimestreDate]),
            VAR trimestreDate = [TrimestreDate]
            VAR year =
                YEAR ( trimestreDate )
            VAR quarterMiddle = 
                CONCATENATE("Trim ",QUARTER(trimestreDate))
            RETURN
                ROW ( 
                "Année, Trim", year & " " & quarterMiddle
        ))
    

    I keep it with no relation and then I can get the selected date to use it as value to filter the measure:

    Total Numbers To Selected Quarter = 
    VAR _max = MAXX(ALLSELECTED(T_Dates_Ind),T_Dates_Ind[TrimestreDate])
    VAR _min = DATE(YEAR(_max)-1,MONTH(_max),DAY(_max))
    RETURN
    CALCULATE(SUM(T_Data_1[Numbers]), FILTER(T_Dates, T_Dates[Date] <= _max && T_Dates[Date] >= _min))
    

    Link to the video the guy shared: https://www.youtube.com/watch?v=44fGGmg9fHI