Power BI: Simple requirement, have two input files as Tables "Previous" and "Current".…
- User
Power BI: Simple requirement, have two input files as Tables "Previous" and "Current". Need to track their first time load timestamp. This column will updated only once a new file source is changed for each "Previous" and "Current", else the value should be same always
- Assistant
To track the first time load timestamp for the "Previous" and "Current" tables in Power BI, you can create a new column using Power Query Editor. Here's a step-by-step guide:
- Load the "Previous" and "Current" tables into Power Query Editor.
- Select the table you want to add the timestamp column to (e.g., "Previous").
- In the "Add Column" tab, click on "Custom Column".
- In the formula bar, enter the following formula:
This formula checks if the current source is different from the previous source. If it is, it assigns the current timestamp using= if [Source] <> #"Previous_Source" then DateTime.LocalNow() else #"Previous_LoadTimestamp"DateTime.LocalNow(). Otherwise, it keeps the previous timestamp value. Replace "Previous_Source" with the name of the column in the "Previous" table that contains the source of the file. Replace "Previous_LoadTimestamp" with the name of the column that will store the timestamp value (this column should exist in the table).
- User
“Previous_Source” and “Previous_LoadTimestamp” not recognized
- Assistant
I apologize for the confusion. In order to reference the previous source and load timestamp, you need to use variables within Power Query Editor. Here's an updated step-by-step guide:
- Load the "Previous" and "Current" tables into Power Query Editor.
- Select the table you want to add the timestamp column to (e.g., "Previous").
- In the "Add Column" tab, click on "Custom Column".
- In the formula bar, enter the following formula:
let previousSource = Table.Column(#"Previous", "Source"){0}, previousLoadTimestamp = Table.Column(#"Previous", "LoadTimestamp"){0}, currentSource = [Source] in if currentSource <> previousSource then DateTime.LocalNow() else previousLoadTimestampThis formula uses variables to store the previous source and load timestamp values from the "Previous" table. It then compares the current source value with the previous source. If they are different, it assigns the current timestamp using
DateTime.LocalNow(). Otherwise, it retains the previous timestamp value. - User
Expression.Error: A cyclic reference was encountered during evaluation.
- Assistant
I apologize for the inconvenience. It seems there is a circular reference issue in the formula I provided. To resolve this error, you can modify the formula as follows:
- Load the "Previous" and "Current" tables into Power Query Editor.
- Select the table you want to add the timestamp column to (e.g., "Previous").
- In the "Add Column" tab, click on "Custom Column".
- In the formula bar, enter the following formula:
let previousSource = Table.Column(#"Previous", "Source"){0}, previousLoadTimestamp = Table.Column(#"Previous", "LoadTimestamp"){0}, currentSource = [Source] in if currentSource <> previousSource then DateTime.LocalNow() else previousLoadTimestampEnsure that you are replacing the table names with the actual names used in your project.