Roger Steinberg
Roger Steinberg

Reputation: 1604

Measure overriding my visual level filter

Situation: I would like to display the average daily sessions for the 2 last calendar months, the difference between both months.

My DAX Measures:

Sessions_Curr = AVERAGEX('Table','Table'[Sessions]) 
    //Calculates the average per grouping
Sessions_Prev = CALCULATE(
    'Table'[Sessions_Curr],
    PREVIOUSMONTH('Date'[Date])
     ) // Calculates the average for the previous month.
Diff Sessions = Sessions_Curr - Sessions_Prev // Difference between the two previous measures.

Next, I add a visual level filter: Relative Date filtering for the last 2 calendar months. Everything is working out so far.

Goal:

However I don't want the second month to show the difference, hence, leaving the cell blank i.e.: like this

+---------------+----------+------+
|   date        | sessions | diff |
+---------------+----------+------+
| 2019 february |     1000 |      |
| 2019 march    |     1500 |  500 |
+---------------+----------+------+

Actualy Result:

+---------------+----------+------+
|   date        | sessions | diff |
+---------------+----------+------+
| 2019 february |     1000 | -200 |
| 2019 march    |     1500 |  500 |
+---------------+----------+------+

Upvotes: 0

Views: 75

Answers (1)

Olly
Olly

Reputation: 7891

Try this - it only displays the measure for the latest selected month:

Diff Sessions = 
VAR ContextDate = LASTDATE( 'Date'[Date] )
VAR LatestSelectedDate = LASTDATE( ALLSELECTED ( 'Date'[Date] ) )
RETURN
    IF ( 
        FORMAT ( ContextDate, "YYYY-MM") = FORMAT ( LatestSelectedDate, "YYYY-MM" ),
        [Sessions_Curr] - [Sessions_Prev],
        BLANK()
    )

Worked example PBIX file: https://pwrbi.com/so_55640430/

Upvotes: 1

Related Questions