Check your eligibility for this 50% exam voucher offer and join us for free live learning sessions to get prepared for Exam DP-700.
Get StartedDon't miss out! 2025 Microsoft Fabric Community Conference, March 31 - April 2, Las Vegas, Nevada. Use code MSCUST for a $150 discount. Prices go up February 11th. Register now.
I have a table with some sample data:
Date | DateIndex | Project | Value | |||
01/01/2020 | 1 | A | 5 | |||
02/01/2020 | 2 | A | 10 | |||
03/01/2020 | 3 | A | 17 | |||
04/01/2020 | 4 | A | 25 | |||
05/01/2020 | 5 | A | 36 | |||
06/01/2020 | 1 | B | 7 | |||
07/01/2020 | 2 | B | 12 | |||
08/01/2020 | 3 | B | 13 | |||
09/01/2020 | 4 | B | 13 | |||
10/01/2020 | 5 | B | 20 | |||
16/02/2020 | 1 | C | 10 | |||
17/02/2020 | 2 | C | 18 | |||
18/02/2020 | 3 | C | 23 |
From this I'm creating a table visual as follows:
Project | Dates | 1 | 2 | 3 | 4 | 5 | |
A | 5 | 10 | 17 | 25 | 36 | |
B | 7 | 12 | 13 | 13 | 20 | |
C | 10 | 18 | 23 |
As you can see, project C will have no value for dates 4 & 5 with it not exisiting in the dataset
What i'm trying to do is create a dax measure that will populate the gaps in the table above with the lastnonblank value for the particular project. So the outcome would be like the below, with the value of 23 being assigned to dates 4 & 5.
Project | Dates | 1 | 2 | 3 | 4 | 5 | |
A | 5 | 10 | 17 | 25 | 36 | |
B | 7 | 12 | 13 | 13 | 20 | |
C | 10 | 18 | 23 | 23 | 23 |
Realistically there would be 10 to 20 projects with various dates, but I would want every projects to go to the max available dateindex, carrying forward any last non blank value
Any ideas?
Solved! Go to Solution.
Hi @RyanBentham
You can try the following steps.
1 Create a Calculated table
New Table = CROSSJOIN(VALUES('Table'[Project]),VALUES('Table'[DateIndex]))
2 Create a Measure
Filled Value =
VAR max_index =
CALCULATE (
MAX ( 'New Table'[DateIndex] ),
ALLEXCEPT ( 'New Table', 'New Table'[Project] ),
NOT ( ISBLANK ( 'New Table'[Value] ) )
)
VAR max_val =
CALCULATE (
MAX ( 'New Table'[Value] ),
FILTER (
ALL ( 'New Table' ),
'New Table'[Project] = SELECTEDVALUE ( 'New Table'[Project] )
&& 'New Table'[DateIndex] = max_index
)
)
VAR res =
IF (
ISBLANK ( SELECTEDVALUE ( 'New Table'[Value] ) ),
max_val,
SELECTEDVALUE ( 'New Table'[Value] )
)
RETURN
IF (
HASONEFILTER ( 'New Table'[Project] ) && HASONEFILTER ( 'New Table'[DateIndex] ),
res,
IF (
HASONEFILTER ( 'New Table'[Project] ),
CALCULATE (
SUM ( 'New Table'[Value] ),
ALLEXCEPT ( 'New Table', 'New Table'[Project] )
),
CALCULATE (
SUM ( 'New Table'[Value] ),
ALLEXCEPT ( 'New Table', 'New Table'[DateIndex] )
)
)
)
The result looks like this:
For more details, you can refer the attached pbix.
Best Regards
Caiyun Zheng
Is that the answer you're looking for? If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Hi @RyanBentham
You can try the following steps.
1 Create a Calculated table
New Table = CROSSJOIN(VALUES('Table'[Project]),VALUES('Table'[DateIndex]))
2 Create a Measure
Filled Value =
VAR max_index =
CALCULATE (
MAX ( 'New Table'[DateIndex] ),
ALLEXCEPT ( 'New Table', 'New Table'[Project] ),
NOT ( ISBLANK ( 'New Table'[Value] ) )
)
VAR max_val =
CALCULATE (
MAX ( 'New Table'[Value] ),
FILTER (
ALL ( 'New Table' ),
'New Table'[Project] = SELECTEDVALUE ( 'New Table'[Project] )
&& 'New Table'[DateIndex] = max_index
)
)
VAR res =
IF (
ISBLANK ( SELECTEDVALUE ( 'New Table'[Value] ) ),
max_val,
SELECTEDVALUE ( 'New Table'[Value] )
)
RETURN
IF (
HASONEFILTER ( 'New Table'[Project] ) && HASONEFILTER ( 'New Table'[DateIndex] ),
res,
IF (
HASONEFILTER ( 'New Table'[Project] ),
CALCULATE (
SUM ( 'New Table'[Value] ),
ALLEXCEPT ( 'New Table', 'New Table'[Project] )
),
CALCULATE (
SUM ( 'New Table'[Value] ),
ALLEXCEPT ( 'New Table', 'New Table'[DateIndex] )
)
)
)
The result looks like this:
For more details, you can refer the attached pbix.
Best Regards
Caiyun Zheng
Is that the answer you're looking for? If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
@RyanBentham , Try a new measure like
if(isblank(max(Table[Value])), calculate(lastnonblankvalue(Table[DateIndex], max(Table[Value])), allexcept(Table, Table[project])), max(Table[Value]))
Thanks, although didn't quite work for me 😞
March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!
Check out the January 2025 Power BI update to learn about new features in Reporting, Modeling, and Data Connectivity.
User | Count |
---|---|
124 | |
79 | |
50 | |
38 | |
38 |
User | Count |
---|---|
195 | |
80 | |
70 | |
51 | |
42 |