The ultimate Fabric, Power BI, SQL, and AI community-led learning event. Save €200 with code FABCOMM.
Get registeredCompete to become Power BI Data Viz World Champion! First round ends August 18th. Get started.
Hi,
I have a quite seemingly simple problem that I can't get my head around. I have data that has three columns: A year column, a dimension column where each dimension repeats every year, and a value column of a decimal number.
I would like to visualize this data ina table and make a measure that returns last years value based on the year column.
How do I do this?
Thanks!
Solved! Go to Solution.
Hi,
If your data are the same as the sample data you provided, this DAX should work :
Last Year Value =
VAR CurrentDim = SELECTEDVALUE( TableTEST[Dimension] )//Get current value for Dimension
VAR CurrentYear = SELECTEDVALUE( TableTEST[Year] ) //Get current value for Year
RETURN
CALCULATE( SUM( TableTEST[Value] ) ,
TableTEST[Year] = CurrentYear-1 , //To get last year
TableTEST[Dimension] = CurrentDim ) //On that dimension
Hi,
If your data are the same as the sample data you provided, this DAX should work :
Last Year Value =
VAR CurrentDim = SELECTEDVALUE( TableTEST[Dimension] )//Get current value for Dimension
VAR CurrentYear = SELECTEDVALUE( TableTEST[Year] ) //Get current value for Year
RETURN
CALCULATE( SUM( TableTEST[Value] ) ,
TableTEST[Year] = CurrentYear-1 , //To get last year
TableTEST[Dimension] = CurrentDim ) //On that dimension
Year | Dimension | Value | Last years value |
2024 | A | 1,5 | |
2024 | B | 2 | |
2024 | C | 3 | |
2024 | D | 2,5 | |
2024 | E | 1 | |
2023 | A | 0,5 | |
2023 | B | 0,8 | |
2023 | C | 0,3 | |
2023 | D | 1 | |
2023 | E | 0,5 |
User | Count |
---|---|
20 | |
8 | |
7 | |
6 | |
6 |
User | Count |
---|---|
29 | |
11 | |
11 | |
9 | |
9 |