Forum Discussion

Aman-K's avatar
Aman-K
Icon for Helper III rankHelper III
1 year ago
Solved

Adding measures in Power BI report

Hi guys,   I have created a report in Power BI which is extracting data from Google Analytics. I want to make few changes in my report so it looks like below :   And a slicer as below: ...
  • Anonymous's avatar
    Anonymous
    1 year ago

    Hi, Aman-K 

    I create a sample table:

     

    Then create a new table, here is the dax:

    TimePeriods = DATATABLE(
        "Period", STRING,
        {
            {"Today"},
            {"Yesterday"},
            {"Last 7 Days"},
            {"Last 14 Days"},
            {"Last 30 Days"}
        }
    )

     

    Create a new measure again, try the following DAX expression:

    SelectedPeriod = 
    VAR _date = MAX('Table'[Date])
    RETURN
    SWITCH(
        SELECTEDVALUE(TimePeriods[Period]),
        "Today", IF(_date = TODAY(), "Today", BLANK()),
        "Yesterday", IF(_date= TODAY() - 1,"Yesterday", BLANK()),
        "Last 7 Days", IF(_date >= TODAY() - 7 && _date<= TODAY(), "Last 7 Days", BLANK()),
        "Last 14 Days", IF(_date >= TODAY() - 14 && _date <= TODAY(), "Last 14 Days", BLANK()),
        "Last 30 Days", IF(_date >= TODAY() - 30 && _date <= TODAY(), "Last 30 Days", BLANK()),
        0
    )

     

    Put this measure in Table view, and put TimePeriods's field in slicer, here is my preview:

     

    How to Get Your Question Answered Quickly

    Best Regards

    Yongkang Hua

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