Forum Discussion
Compare data using a given filter
- 9 years ago
Hey,
one possible solution could be to create a measure that calculates the amount of previous year like so:
amount PY =
IF(HASONEFILTER('Table1'[Year]),
var py = values('Table1'[Year]) -1
return
CALCULATE(SUM('Table1'[Amount]),
'Table1'[Year] = py
),
BLANK()
)Now you can use both measures in any visualization, if more than one year is selected or NONE, the measure returns a BLANK() / NULL value
Hope this is what you are looking for
Hey,
one possible solution could be to create a measure that calculates the amount of previous year like so:
amount PY =
IF(HASONEFILTER('Table1'[Year]),
var py = values('Table1'[Year]) -1
return
CALCULATE(SUM('Table1'[Amount]),
'Table1'[Year] = py
),
BLANK()
)
Now you can use both measures in any visualization, if more than one year is selected or NONE, the measure returns a BLANK() / NULL value
Hope this is what you are looking for
- GeraSanz119 years agoFrequent Visitor
Thank you so much!
Just what i needed, i don't understand very well the whole formula (the py for example) but for sure is what i was looking for... ill look for more documentation!
THX
- TomMartens9 years agoSuper User
Hey,
what happens is this
- Check if just one year is selected in the slicer
- if just one year is selected
- define a variable py it's just a name for previous year
- use values() to return a table with just one column, the special part about values() is this, if the table contains just one row it can be used as a skalar value and it's possible to subtract 1
- use the variable to filter the table where the year column equals the variable
- if more than year or none year is selected return blank()
- if just one year is selected
- Check if just one year is selected in the slicer