March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount! Early bird discount ends December 31.
Register NowBe one of the first to start using Fabric Databases. View on-demand sessions with database experts and the Microsoft product team to learn just how easy it is to get started. Watch now
Hi Community,
I have a dataset table named as "IBNS".
Under it, I have 3 columns as follow:-
1. KEY (Data type - text)
2. Date (Data type - Short Date)
3. RRT - (Data type - Decimals)
I want to add the values of second row into the first one, and I want that for each category.
For example: Add the 12/31/2024 date data to 12/31/2023 date for one category and same like that for othe category as well.
You can get the idea of what I want from the Screenshot attached.
I have tried the code below, But it is not working.
Solved! Go to Solution.
Hi @Birinder,
Sure, please try this CC:
And the same in plain text:
PrevSum v2 =
VAR CurrentKey = [KEY]
VAR CurrentDate = [Date]
VAR PrevYear = CALCULATE ( YEAR ( MAX ( data[Date] ) ), ALL ( data ), data[KEY] = CurrentKey, data[Date] < CurrentDate )
VAR PrevRRT = MINX ( FILTER ( ALL ( data ), AND ( [KEY] = CurrentKey, YEAR ( [Date] ) = PrevYear ) ), [RRT] )
RETURN IF ( ISBLANK ( PrevRRT ), 0, [RRT] + PrevRRT )
Best Regards,
Alexander
Hello @Birinder,
I'd solve your task with the following calculated column:
Here's the [DAX] code in plain text:
PrevSum =
VAR CurrentKey = [KEY]
VAR PrevYear = YEAR ( [Date] ) - 1
VAR PrevRRT = MINX ( FILTER ( ALL ( data ), AND ( [KEY] = CurrentKey, YEAR ( [Date] ) = PrevYear ) ), [RRT] )
RETURN IF ( ISBLANK ( PrevRRT ), 0, [RRT] + PrevRRT )
Best Regards,
Alexander
Hi @barritown,
Thanks for the reply.
The code works almost perfectly, however there is still one issue.
The code will work when we have continous series of years i,e 2020,2021,2022 and so on.
There are some cases where there are year skips such as 2020,2022,2023,2026.
In those cases the results are not coming up right and they are zero.
Please ignore the AMT column.
Is there a way only for PrevYear varible , via which we can choose earlier period than the current one.
Like in screenshot, for second last row:
12/31/2045 date should refer to its very previous date i.e. 12/31/2043, which is picking 12/31/2044 as of current solution and giving the values as zero.
Do you know a way by which we can achieve this.
Many thanks in Advance.
Hi @Birinder,
Sure, please try this CC:
And the same in plain text:
PrevSum v2 =
VAR CurrentKey = [KEY]
VAR CurrentDate = [Date]
VAR PrevYear = CALCULATE ( YEAR ( MAX ( data[Date] ) ), ALL ( data ), data[KEY] = CurrentKey, data[Date] < CurrentDate )
VAR PrevRRT = MINX ( FILTER ( ALL ( data ), AND ( [KEY] = CurrentKey, YEAR ( [Date] ) = PrevYear ) ), [RRT] )
RETURN IF ( ISBLANK ( PrevRRT ), 0, [RRT] + PrevRRT )
Best Regards,
Alexander
Thanks @barritown
It is working now.
Thanks a lot for this.
Also ,Thanks to @Ahmedx for the soluton.
Peace.
March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!
User | Count |
---|---|
93 | |
91 | |
90 | |
80 | |
49 |
User | Count |
---|---|
160 | |
145 | |
103 | |
72 | |
55 |