Forum Discussion

alihijazi's avatar
alihijazi
Helper I
10 years ago

parameters

Hello I'm new to powerBI

Is there a way to create a variable or parameter like vMaxYear = year(max(TrxDate)) and then use this parameter or variable in the filter of a calculate Dax expression?

2 Replies

  • Eric_Zhang's avatar
    Eric_Zhang
    Microsoft Employee

    alihijazi

    You could declare a variable as below

    LatestYearSumTotal = 
    VAR MaxYear = YEAR(max(Orders[OrderDate]))
    RETURN
    CALCULATE(
    SUM(Orders[Freight]),FILTER(Orders,YEAR('Orders'[OrderDate])=MaxYear))