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.
Hi,
I have table "prod_snapshot", that is snapshot data of customer records. The table has a calculated column "default tagi", that tags default with an IF-statement, returning either 1 or 0 based on whether the customer is defaulted or not. I need a column that returns the previous value of a default tagi column.
I have used syntax:
Could anyone help me with this?
Solved! Go to Solution.
Replace the CALCULATETABLE with FILTER, that works in the sample I've mocked up.
@Anonymous could you please try the below DAX code
You can use TOPN
previous default =
var currentLoan = 'Table'[loan_id]
var currentYearMonth = 'Table'[Year Month order]
return SELECTCOLUMNS( TOPN(1, CALCULATETABLE( REMOVEFILTERS('Table'),
'Table'[loan_id] = currentLoan && 'Table'[Year Month order] < currentYearMonth ),
'Table'[Year Month order], DESC),
"@value", 'Table'[default tagi]
)
Thanks for your reply! Unfortunately, it doesn't work. I replaced REMOVEFILTERS() with ALL(), as apparently REMOVEFILTERS cannot be used with calculatetable expression, but still throws this error message:
Do you have multiple entries in a month for a loan ? If so you may need to add a unique index column using Power Query and you can then add that index column as another sort on the TOPN, that should only return 1 value per loan then
Yes I have, but I want that the previous default column considerers only those values from default tagi -column that are from different month.
I made Index column, that gives different index for every report date:
The problem with your index column is that it will give the same result to different entries with the same date, and so you have the same problem as before.
I would use Power Query to add the column. Sort by the date column then add an index column, doesn't matter whether it starts from 0 or 1.
That will guarantee that there will be a unique index and you can use that in TOPN
Thanks, the index column was easy to do in Power Query as you told.
The TOPN-function works now, but now previous default column seems to return"1" for every report date:
Was the TOPN -function correct as I posted it or should the Index column be included in a different way?
Replace the CALCULATETABLE with FILTER, that works in the sample I've mocked up.
That works, thanks a lot for your help!
define table Loans =
SELECTCOLUMNS(
{
(1, 1, 0),
(1, 2, 0),
(1, 3, 1),
----------
(2, 1, 0),
(2, 2, 1),
(2, 3, 1)
},
"loan_id", [Value1],
"ym_order", [Value2],
"def_tagi", [Value3]
)
EVALUATE
ADDCOLUMNS(
Loans,
"prev_def",
var curr_loan_id = Loans[loan_id]
var curr_ym_order = Loans[ym_order]
var prev_def_tagi =
MAXX(
filter(
Loans,
Loans[loan_id] = curr_loan_id
&&
Loans[ym_order] = curr_ym_order - 1
),
Loans[def_tagi]
)
return
COALESCE( prev_def_tagi, 0 )
)
Run this in DAX Studio. The definition of "prev_def" is what you need.
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 |
---|---|
12 | |
11 | |
8 | |
7 | |
7 |
User | Count |
---|---|
20 | |
14 | |
11 | |
10 | |
10 |