Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
6 years ago
Solved

Slicer with if statement

I have a slicer that contains multiple quarters. I will like to have a formula where if i click on Q1 2020, the formula will sum up the revenue  of  the prior yr revenue (ie Q1 2019).  One of the car...
  • v-lid-msft's avatar
    6 years ago

    Hi Anonymous ,

     

    We can use two ways to meet your requirement.

    First way,

    1. We need to create a table that contains date and quarter.
    Dates = ADDCOLUMNS (
        CALENDAR ( "2018/1/1", "2020/12/31" ),
        "Year Quarter Number", [date] * 100
            + QUARTER ( [date] ))
     

     

    1. Then we can create two measures to get the result,
    current revenue =
    var current__ = SELECTEDVALUE(Dates[Year Quarter Number])
    return
    CALCULATE(SUM('Table'[revenue]),'Table'[Year Quarter Number]=current__)

     

    LQ revenue =
    var current__ = SELECTEDVALUE(Dates[Year Quarter Number])
    return
    CALCULATE(SUM('Table'[revenue]),'Table'[Year Quarter Number]=current__-100)

     

    The slicer uses Dates[Year Quarter Number].

     

    Second way,

    1. We need to create a Dates table like first way.

     

    1. We can use the SAMPERIODLASTYEAR function to create the last year quarter measure.
    Measure = CALCULATE(SUM('Table'[revenue]),SAMEPERIODLASTYEAR(Dates[Date]))

     

    1. At last we need to create a relationship between two tables based on date. Then we can get the result like this,
     

     

     

    If it doesn’t meet your requirement, could you please show the exact expected result based on the table that we have shared?

     

    BTW, the first way doesn’t need to create a relationship, and pbix file as attached.

     

    Best regards,