Forum Discussion
How to pull a balance date and master data date
Hello, I have two tables like below: one balance and one master data
Is there a measure I can create that would allow me to for example select the 31-Jan-25 date from the balance table and then select from the masterdata table the most recent date that is <= the date selected from the balance table which in this case would be the 31-Dec-24 record. This would allow me to have lastest masterdata version for the balance record. I have joined these two tables on account number.
Hi bweiland ,
I understand. Below is the final image of the output. Is this what you are looking for when you visual? This was done bascially by inputing an index column in the original table just like the one shown in the second image below. This was created to uniquely identify every row.
I'll leave the link to the file to check out the measures and columns. Thanks
https://drive.google.com/file/d/1EL4CyHjGUa3D__w7byn3FhXLteC-WBvX/view?usp=sharing
9 Replies
- v-kpoloju-msftCommunity Support
Hi bweiland,
Thank you for reaching out to the Microsoft fabric community forum.
After thoroughly reviewing the details you provided, I was able to reproduce the scenario, and it worked on my end. I have used it as sample data on my end and successfully implemented it.
Dax Measure for Latest Master Data date:Latest MasterData Date = VAR SelectedDate = MAX(Balance[BalanceDate]) VAR CurrentAcct = SELECTEDVALUE(Balance[AccountNumber]) RETURN CALCULATE ( MAX(MasterData[MasterDate]), FILTER ( MasterData, MasterData[AccountNumber] = CurrentAcct && MasterData[MasterDate] <= SelectedDate ) )
Dax Measure for Latest Risk Rating:Latest Risk Rating = VAR SelectedDate = MAX(Balance[BalanceDate]) VAR CurrentAcct = SELECTEDVALUE(Balance[AccountNumber]) VAR LatestDate = CALCULATE ( MAX(MasterData[MasterDate]), FILTER ( MasterData, MasterData[AccountNumber] = CurrentAcct && MasterData[MasterDate] <= SelectedDate ) ) RETURN CALCULATE ( MAX(MasterData[RiskRating]), FILTER ( MasterData, MasterData[AccountNumber] = CurrentAcct && MasterData[MasterDate] = LatestDate ) )
Relationship between both tables:
outcome:
I am also including .pbix file for your better understanding, please have a look into it:
If this post helps, then please give us ‘Kudos’ and consider Accept it as a solution to help the other members find it more quickly.
Thank you for using Microsoft Community Forum.- v-kpoloju-msftCommunity Support
Hi bweiland,
May I ask if you have resolved this issue? If so, please mark the helpful reply and accept it as the solution. This will be helpful for other community members who have similar problems to solve it faster.
Thank you.
- bweilandRegular Visitor
This did not work.
1) There is reference to a 'MasterData[RiskRating] field which I do not have.
2) When I tried the Latest MasterData Date measure it produced a result for 2025-02-28 of $400 for Dog which is the correct Master data dimension 'Dog' but incorrect balance. It seems the measure is cummulative sum versus being just $200.
I found that creating the below calculated column results in the desired result:
Animal Type Column =VAR CurrentAccount = 'Fact'[Account Number]VAR CurrentFactDate = 'Fact'[Date]VAR ClosestDateRow =TOPN(1,FILTER(MasterData,MasterData[Account Number] = CurrentAccount),ABS(DATEDIFF(Masterdata[Date], CurrentFactDate, DAY)),ASC)RETURNMAXX(ClosestDateRow, MasterData[Animal Type])
- SundarRajSuper User
Hi bweiland , here's a Power Query solution you can try out by pasting it in the Advance Editor:
1. Please make sure that you have two Tables: TableBalance and TableMasterData (This Table is being referred in the TableBalance Data as you'll see in the code). Thanks. Do let me know if you have any queries regarding the same.Here's the code:
let
TableBalance = #table(
{"Account Number", "Date", "Balance"},
{
{1, #date(2025, 1, 31), 100},
{1, #date(2025, 1, 31), 100},
{1, #date(2025, 3, 31), 200}
}
),Transform = Table.AddColumn(
TableBalance,
"Record",
each Table.FillDown(
Table.FromColumns(
Table.ToColumns(TableMasterData) & { { _[Date] } }
),
{"Column4"}
)
),Record = Table.TransformColumns(
Transform,
{
"Record",
each Table.FirstN(
Table.Sort(
Table.SelectRows(
Table.AddColumn(_, "Check", each [Column4] >= [Column2]),
each [Check] = true
),
{ "Column2", Order.Descending }
),
1
)
}
),Cols = List.Transform(
List.Skip(Table.ColumnNames(TableBalance)),
each "Master " & _
),Table = Record,
Expand = Table.ExpandTableColumn(
Table,
"Record",
{"Column2", "Column3"},
Cols
)
in
Expand- bweilandRegular Visitor
Yes, this works but it can't be displayed as measure or column so how to do incorporate the results into a visual?
- SundarRajSuper User
Hi bweiland ,
I understand. Below is the final image of the output. Is this what you are looking for when you visual? This was done bascially by inputing an index column in the original table just like the one shown in the second image below. This was created to uniquely identify every row.
I'll leave the link to the file to check out the measures and columns. Thanks
https://drive.google.com/file/d/1EL4CyHjGUa3D__w7byn3FhXLteC-WBvX/view?usp=sharing