Forum Discussion
DAX for lastyear data
Hello All,
this is the table i have
| Name | Bal | Exp | Fy |
| a | 9 | 10 | 2023 |
| a | 15 | 20 | 2024 |
| a | 10 | 15 | 2025 |
the requirement is that i need to create a measure or a column which will give me balance total (last years bal + last years Exp)
so if I select Fy 2023 then i should get the below table
balance total is 0 because we don't have any data for last year
| Name | Bal | Exp | balance total |
| a | 9 | 10 | 0 |
now if we select Fy2024 i need to get the below
balance total is 19 (last year bal + last year Exp )
| Name | Bal | Exp | balance total |
| a | 15 | 20 | 19 |
hi Anonymous
here comes the verified code for calculated column:
BalanceTotal = VAR _pre = FILTER( tableName, tableName[name]=EARLIER(tableName[name]) &&tableName[fy]=EARLIER(tableName[fy])-1 ) VAR _balpre = MINX( _pre, tableName[Bal]) VAR _exppre = MINX(_pre, tableName[Exp]) RETURN _balpre + _exppreAnd result:
7 Replies
- Arul
Super User
Anonymous ,
Can you try this measure?
Bal + Exp Last Year = VAR _selectedYear = IF ( HASONEVALUE ( Test[Fy] ), FIRSTNONBLANK ( Test[Fy], Test[Fy] ), BLANK () ) - 1 RETURN IF ( CALCULATE ( SUMX(Test,Test[Bal]+Test[Exp]), ALL ( Test ), Test[Fy] = _selectedYear ) = 0, 0, CALCULATE ( SUMX(Test,Test[Bal]+Test[Exp]), ALL ( Test ), Test[Fy] = _selectedYear ) )Thanks,
- FreemanZ
Super User
hi Anonymous
here comes the verified code for calculated column:
BalanceTotal = VAR _pre = FILTER( tableName, tableName[name]=EARLIER(tableName[name]) &&tableName[fy]=EARLIER(tableName[fy])-1 ) VAR _balpre = MINX( _pre, tableName[Bal]) VAR _exppre = MINX(_pre, tableName[Exp]) RETURN _balpre + _exppreAnd result:
- amitchandak
Super User
Anonymous , Create a new table with distinct year and join it with the year of your table, Say the table name is date
//Only year vs Year, not a level below
This Year = CALCULATE(sumX('Table', [Balance] + [Exp]),filter(ALL('Date'),'Date'[Year]=max('Date'[Year])))
Last Year = CALCULATE(sumX('Table', [Balance] + [Exp]),filter(ALL('Date'),'Date'[Year]=max('Date'[Year])-1))- AnonymousNot applicable
Hello There,
Thanks for your response
the requirement is that i create one measure which will show the balance total
in the slicer for year if i select 2023 then the balance total is 0 if i select any other year then the total is addition of last years bal and exp
- FreemanZ
Super User
hi Anonymous
you might create a column like this
BalanceTotal =VAR _pre =FILTER(tableName,tableName[name]=ERALIER(tableName[name])&&tableName[fy]=ERALIER(tableName[fy]))-1)VAR _balpre =MINX(_pre, tableName[Bal])VAR _exppre =MINX(_pre, tableName[Exp])RETURN_balpre + _exppre - Padycosmos
Solution Sage
Hope this helps
- AnonymousNot applicable
Hello There,
Thanks for your responds
But it won’t give me 2023 values right I need to showname bal ex fy bal total a 9 10 2023 0 a 15 20 2024 19