Forum Discussion

apai1990's avatar
apai1990
Frequent Visitor
2 years ago
Solved

Need help with parameter comparison in Power BI

Hello,   I'm a Tableau user and new to Power BI, I got stuck on how to use parameters to create a condition that represents TRUE and FALSE so that I can use them in the filter. I did use the VAR re...
  • hackcrr's avatar
    2 years ago

    Hi, apai1990 

    I have the following data table:

    I have the following two parameters:

    I created a metric using the following DAX expression:

    IsInPeriod = 
    VAR pyS = SELECTEDVALUE('Start year'[Start year])  
    VAR pyE = SELECTEDVALUE('End Year'[End Year])  
    VAR ppS = SELECTEDVALUE(SalaryPeriods[SalaryPeriod])  
    VAR pp = SELECTEDVALUE(Payments[Payment Period]) 
    VAR py = SELECTEDVALUE(Payments[Payment Year])  
      
    RETURN  
        IF (  
            NOT ISBLANK(pyS) && NOT ISBLANK(pyE) && NOT ISBLANK(ppS),  
            IF (  
                pyS = pyE,  
                IF (py = pyS && pp = ppS, "In Period", "Not In Period"),  
                IF (py = pyS || py = pyE || (py > pyS && py < pyE) && pp >= ppS, "In Period", "Not In Period")  
            ),  
            "Parameters Not Set"  
        )

    Use the following fields in the table vision object:

    The results are as follows:

     

     

    Best Regards,

    hackcrr

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