Power BI is turning 10, and we’re marking the occasion with a special community challenge. Use your creativity to tell a story, uncover trends, or highlight something unexpected.
Get startedJoin us for an expert-led overview of the tools and concepts you'll need to become a Certified Power BI Data Analyst and pass exam PL-300. Register 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.
This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.
Check out the June 2025 Power BI update to learn about new features.
User | Count |
---|---|
72 | |
71 | |
56 | |
38 | |
35 |
User | Count |
---|---|
85 | |
66 | |
59 | |
46 | |
45 |