Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
Salvador
Responsive Resident
Responsive Resident

Storing and using information from a dynamic data source using PBI desktop.

Hello,

 

This is something that I've worked in for a couple of months, and have been successfully using it for 3 months, and now would like to share with the community. If you want to know where this comes from, please visit this post.

 

 

Now I'm going to explain the whole process, as detailed as possible.

 

1) Connect Power BI to a data source.  

 

For this example, I’m going to connect to a web page that publishes information regarding IBEX 35

1.png2.png3.png

 

After that, we will create a column: Refreshment date = now ()

 

*For users that use regional settings different to English ones, I recommend to disable time intelligence, under Options, Data Load.

 

2) Prepare the system to use the script.

 

I use a Virtual Machine for this, but it can be done from any pc that meets the requirements.

 

First, you will need to install Power Shell’s Package Manager. https://www.microsoft.com/en-us/download/details.aspx?id=51451

 

Second, run PowerShell as an admin, and follow these steps. (from https://stackoverflow.com/questions/29828756/the-term-install-module-is-not-recognized-as-the-name-o...)4.png

 

Third, download and install SQL_AS_AMO.msi and SQL_AS_ADOMD.msi from https://www.microsoft.com/download/details.aspx?id=52676

Now, you are ready to edit the script.

 

3) Edit the script.

 

You can download it from my onedrive. Instructions are placed inside the script.

 

4) Use the task scheduler.

 

Since we don’t want to run the script manually every day (weekends included), let´s program that task!

Download this file first, then open the task scheduler.

Then, select where you want to store the task, and import it.5.png

 

 

I have it set to 10 PM every day, you can change it. Then go to actions, and update the file path to the PowerShell script.

After that, just to check everything is working fine, I’d run the task, just in case…

 

5) Add the stored information to the data model.

 

Now we can go back to power bi. At this point, I prefer to make a copy of the pbix file, with a different name, so that the one that is being used for the script is as simple as it can be.

First, get data from a folder, should be the folder with your table(s) name, inside the “daily” folder created on your desktop.

6.png

Then, click on Edit, Combine & Edit.

7.png

 

 

We check that everything is in order…8.png

 

 

Now we have two tables, one with the information from the dynamic feed, and one from the info that we have stored. Now we need to rename the (2) table, and the columns.9.png

 

 

I recommend doing it from the Query Editor.

10.png

 

 

6) Appending Queries

 

Now is time to put all the info together, and for that we will “Append Queries as new”.

From the query editor, Append queries as new.11.png

12.png

 

Now we have everything in one table, I recommend changing the appends name, and hiding the other two tables in the report view.13.png

 

 

 

After that, we will create a column: Data's Date = IF (ISBLANK (FinalData [Refreshment date]); now (); FinalData [Refreshment date])

That way, we will be able to know when that data was stored.

14.png

 

 

 

In my case, since I need to use the “live” data and the historical one, I use another column to separate it:

Historical Data = "Data from " & DATEDIFF (FinalData [Data's Date (Text)]; NOW (); DAY) & " Day(s) ago"15.png


In case you need to establish relationships between tables, by using this script to store historical data, you will no longer have unique ids to stablish relationships in some cases, what I do to solve that issue, is to add the date to the ids.

 

xxxID = table1[_xxxid_value] & FORMAT(Table1[Data's Date];"MM/DD/YYYY")

If you are using power bi desktop, you don’t need to do anything else, but if you want to publish it to pbi online, you will need to set up a data gateway.

 

 

I hope you’ve enjoyed this long guide, in case you have any doubts, questions, or would like to add something, please feel free to send me an email to salva.gm@outlook.es

 

I would also like to give my special thanks to Jorge Diaz, for his guidance and support whilst developing this, without him, this would have probably ended as a “happy idea”, and to Imke, from thebiccountant.com, for pointing us the right direction.

 

3 REPLIES 3
Kaeso
New Member

Quick question.  It looks like the data pull is managed through the task scheduler, what about the combining of files?  Is that a manual process?  Does it need to be done at every refresh to preserve the data creation timestamp?

Salvador
Responsive Resident
Responsive Resident

Hello Kaeso,

 

It's explained in the post, you have to use folder as data source for the csv files, so, it will add everything that is in that folder every time it is refreshed Smiley Very Happy

Regarding the data timestamp, look for "After that, we will create a column: Data's Date = IF (ISBLANK (FinalData [Refreshment date]); now (); FinalData [Refreshment date])

That way, we will be able to know when that data was stored." in the post. By creating this on the data that we want to store, when it is stored in a csv, it will take the current time as a timestamp, and every csv created using the script will have it's own timestamp.

 

If you have any other doubts, dont hesitate to ask Smiley Very Happy

 

Regards,

Salva.

 

Hi,

 

I am trying to create trend KPIs from Power Bi and this looks like a potential solution.

 

The script is currently unavailable, any change of a reupload? 

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.