Forum Discussion
Carry Forward Values until Change
- 3 years ago
The method I posted was using measures.
If you want it as a calculated column, use:
Filled Value = VAR _LNB = CALCULATE ( MAX ( 'Table'[Date] ), FILTER ( 'Table', 'Table'[Date] <= EARLIER ( 'Table'[Date] ) && NOT ISBLANK ( 'Table'[Daily Rate] ) ) ) RETURN LOOKUPVALUE ( 'Table'[Daily Rate], 'Table'[Date], _LNB )
THnaks for the help Paul, but I am having the same issue. I attached a file with both an excel and a PBIX for refrence
DropBox
The error you're getting is because you need to write the proper field name as per your dataset. I believe it is '3. RATES_TABLE_MMMF'[DAILY-RATE]
(instead of '3. RATES_TABLE_MMMF'[Daily Rate] which is what you now have in your code)
- danielhough3 years agoHelper II
You're Right, that did fix it, but for some reason its still not populating the blanks with 1.1404
Heres the code:
Filled Value = VAR _LNB = CALCULATE ( MAX ( '3. RATES_TABLE_MMMF'[Date] ), FILTER ( '3. RATES_TABLE_MMMF', '3. RATES_TABLE_MMMF'[Date] <= EARLIER ( '3. RATES_TABLE_MMMF'[Date] ) && '3. RATES_TABLE_MMMF'[Unique key] = EARLIER ( '3. RATES_TABLE_MMMF'[Unique key] ) && NOT ISBLANK ( '3. RATES_TABLE_MMMF'[Daily_Rate] ) ) ) RETURN CALCULATE ( MAX ( '3. RATES_TABLE_MMMF'[Daily_Rate] ), FILTER ( '3. RATES_TABLE_MMMF', '3. RATES_TABLE_MMMF'[Date] = _LNB && '3. RATES_TABLE_MMMF'[Unique key] = EARLIER ( '3. RATES_TABLE_MMMF'[Unique key] ) ) ) - PaulDBrown3 years agoCommunity Champion
Whcih field sets the Rate? I'm going to do in Power Query which is much mor efficient for these types of tasks
- danielhough3 years agoHelper II
The rate is brought into the table via a related forumla based on the uniuqe Key
- PaulDBrown3 years agoCommunity Champion
So the values have to be filled in based on date and Unique key?
- danielhough3 years agoHelper II
Thats correct, the Unique Key is essentially the Month/Year/Code that connects to a 1:1 match with a Rate table. This case here, there was no entry for August, because the rate was unchnaged from July. so the result is all blanks until the rate chaged in September
- PaulDBrown3 years agoCommunity Champion
See if this code in Power Query works for you:
let Source = Excel.Workbook( File.Contents("D:\OneDrive\1 Shared web\Comm PBIs\Filled Value\Power BI\Book2.xlsx"), null, true ), Sheet1_Sheet = Source{[Item = "Sheet1", Kind = "Sheet"]}[Data], #"Promoted Headers" = Table.PromoteHeaders(Sheet1_Sheet, [PromoteAllScalars = true]), #"Changed Type" = Table.TransformColumnTypes( #"Promoted Headers", { {"Date", type date}, {"Unique Key", type text}, {"DAILY_RATE", type number}, {"RT_RATE_INDEX_CCY", type text}, {"DAILY_TABLE_KEY", type text} } ), #"Sorted Rows2" = Table.Sort( #"Changed Type", {{"RT_RATE_INDEX_CCY", Order.Ascending}, {"Date", Order.Ascending}} ), #"Duplicated Column" = Table.DuplicateColumn(#"Sorted Rows2", "DAILY_RATE", "RATE"), #"Group" = Table.Group( #"Duplicated Column", {"RT_RATE_INDEX_CCY"}, {{"All_Rows", each Table.FillDown(_, {"RATE"}), type table}} ), #"Expanded All_Rows" = Table.ExpandTableColumn( Group, "All_Rows", {"Date", "Unique Key", "DAILY_RATE", "RT_RATE_INDEX_CCY", "DAILY_TABLE_KEY", "RATE"}, {"Date", "Unique Key", "DAILY_RATE", "RT_RATE_INDEX_CCY.1", "DAILY_TABLE_KEY", "RATE"} ), #"Changed Type3" = Table.TransformColumnTypes( #"Expanded All_Rows", {{"Date", type date}, {"RATE", type number}, {"DAILY_RATE", type number}} ), #"Reordered Columns" = Table.ReorderColumns( #"Changed Type3", { "RT_RATE_INDEX_CCY", "Date", "Unique Key", "DAILY_RATE", "RATE", "RT_RATE_INDEX_CCY.1", "DAILY_TABLE_KEY" } ) in #"Reordered Columns"New file attached
- danielhough3 years agoHelper II
Thank you so much for your continued help! the data I sent earler was a cut out of my overall model. In my model, my data is being retrieved from an oracle database and the table I provided is the result of a daily table:
3. RATES_TABLE_MMMF = Var Cal = CALENDAR(DATE(YEAR(TODAY())-1,1,1),max('PS_RT_RATE_TBL'[EFFDT])) Var Des = SUMMARIZE('PS_RT_RATE_TBL',PS_RT_RATE_TBL[RT_RATE_INDEX_CCY]) VAR TAB = GENERATE(Cal,Des) Return TABOther columns:
DAILY_RATE = RELATED(PS_RT_RATE_TBL[RATE_MULT]) Unique Key = MONTH([date])&YEAR([date])&[RT_RATE_INDEX_CCY] DAILY_TABLE_KEY = [DATE]&[RT_RATE_INDEX_CCY]How may I adapt your code to these paramaters?
- PaulDBrown3 years agoCommunity Champion
The Power Query method need the tables in Power Query, and Calculated tables are no accesible in PQ . So we need the imported
'PS_RT_RATE_TBL'to be able to build the whole table in PQ instead of using DAX