Forum Discussion

Woody4265's avatar
Woody4265
Regular Visitor
2 years ago

Dynamic Slicers

I'm new to power bi and it capabilities, If I expalin my dilema then hopefullysomeone will have the answer.

 

I have a disconected table thatretrieves the last 3 year from a mydataI.E.2023,2022&2021 this is placedin a slicer

 

Code = 

Year Slicer = 
var _Year = CALCULATETABLE(
                     VALUES('Quotes View'[ActionYear]),
                     FILTER('Quotes View','Quotes View'[ActionYear] >= Year(TODAY())-2)
)
Var Results = _Year
RETURN
Results

 

This produces the slicer with 3 values. I also have an aditional dynamic slicer that uses:

 

Period Selection = 
var TodaysDate = Today()
var YearStart = CALCULATE(STARTOFYEAR('Quotes View'[ActionedDate]),Year('Quotes View'[ActionedDate]) = Year(TodaysDate))
var QuarterStart = CALCULATE(STARTOFQUARTER('Quotes View'[ActionedDate]),Year('Quotes View'[ActionedDate]) = Year(Year(TodaysDate)) ,QUARTER('Quotes View'[ActionedDate]) = QUARTER(TodaysDate))
var MonthStart = CALCULATE(STARTOFMONTH('Quotes View'[ActionedDate]),Year('Quotes View'[ActionedDate]) = Year(Year(TodaysDate)),Month('Quotes View'[ActionedDate]) = Month(TodaysDate))
var WeekStart = TodaysDate - WEEKDAY(TodaysDate,2)+1
Var Results =
    UNION (
        ADDCOLUMNS(
            CALENDAR(YearStart,TodaysDate),
            "Selection","YTD",
            "SelectionId",1
        ),
        ADDCOLUMNS(
            CALENDAR(QuarterStart,TodaysDate),
            "Selection","QTD",
            "SelectionId",2
        ),
        ADDCOLUMNS(
            CALENDAR(MonthStart,TodaysDate),
            "Selection","MTD",
            "SelectionId",3
        ),
        ADDCOLUMNS(
            CALENDAR(WeekStart,TodaysDate),
            "Selection","WTD",
            "SelectionId",4
        ),
        ADDCOLUMNS(
            CALENDAR(TODAY(),TodaysDate),
            "Selection","Today",
            "SelectionId",5
        )
    )
    RETURN
    Results

 

This return aslicer with the following Option YTD,QTD,MTD,WTD  Today, the issue I have is the above code is only for the current year, I tried numorouse variations to input the value from the year slicer but none work. I want to be able to select a year an the other slicer displays the data for the period seleted for the year selected.

Any assistance would be greatly appreciated.

1 Reply