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

Grow your Fabric skills and prepare for the DP-600 certification exam by completing the latest Microsoft Fabric challenge.

Reply
Anonymous
Not applicable

To automate data load with system date

Hi All,

 

I have a dashboard for which data is coming from stored procedures in SQL server. I want my dashboard to have the lastest data.

Can anyone suggest me how yo automate the data load into Power BI with system date.

 

The stored procedures run when we give system date as input parameter.

 

 

Please suggest

 

 

 

1 ACCEPTED SOLUTION

HI @Anonymous,

It seems like you missed the right 'quotation' in your query that stored the 'store procedures', please add it to confirm if the issue fixed:

 

    Source =
        Sql.Database(
            "test",
            "test",
            [
                Query =
                    "DECLARE @return_value int EXEC @return_value = [dbo].[usp_Response_SLA] @date = "
                    & Date.ToText(Date.From(DateTime.LocalNow()),"MM/dd/yyyy")
            ]
        )

 

snapshotsnapshot

Notice:

1.'02-09-2021' will be generated by the right part M query function, you not need to add them to your query.

2. I also modify the generated date functions to get the same format as you shared.

Regards,

Xiaoxin Sheng

Community Support Team _ Xiaoxin
If this post helps, please consider accept as solution to help other members find it more quickly.

View solution in original post

6 REPLIES 6
v-shex-msft
Community Support
Community Support

Hi @Anonymous,

I think you can try to parameterize your connection string to send the current system date and use it as a parameter to get data.

M query DateTime.LocalNow 
Regards,

Xiaoxin Sheng

Community Support Team _ Xiaoxin
If this post helps, please consider accept as solution to help other members find it more quickly.
Anonymous
Not applicable

Thank you for the reply can you please elaborate the steps in details.

Hi @Anonymous,

You can invoke your store procedures with the function that I mention.

Sample steps:

1. Past the 'Stored Procedure' string into the SQL statement of your connector: (advanced option)

EXECUTE [dbo].[xxxxxxx] @date= xxxxx

Import data from a database using native database query 

2. Enter to 'query editor' and navigate to the 'advanced editor' to modify the steps to concatenate the raw string with 'DateTime' functions:

    Source =
        Sql.Database(
            "test",
            "test",
            [
                Query =
                    "EXECUTE [dbo].[xxxxxxx] @Date= "
                    & Text.From(DateTime.LocalNow())
            ]
        )

Power Query and Stored Procedures with Parameters 

Regards,

Xiaoxin Sheng

Community Support Team _ Xiaoxin
If this post helps, please consider accept as solution to help other members find it more quickly.
Anonymous
Not applicable

Hi @v-shex-msft ,

 

Thank you for the reply, I tried using this but its thorwing below error.

neelofarshama_0-1613385903291.png

The below is my Strored Procedure in Power BI

DECLARE @return_value int

EXEC @return_value = [dbo].[usp_Response_SLA]
@date = '02-09-2021'
& Text.From(DateTime.LocalNow())       -----------------I added as per your suggestion here

SELECT 'Return Value' = @return_value

 

HI @Anonymous,

It seems like you missed the right 'quotation' in your query that stored the 'store procedures', please add it to confirm if the issue fixed:

 

    Source =
        Sql.Database(
            "test",
            "test",
            [
                Query =
                    "DECLARE @return_value int EXEC @return_value = [dbo].[usp_Response_SLA] @date = "
                    & Date.ToText(Date.From(DateTime.LocalNow()),"MM/dd/yyyy")
            ]
        )

 

snapshotsnapshot

Notice:

1.'02-09-2021' will be generated by the right part M query function, you not need to add them to your query.

2. I also modify the generated date functions to get the same format as you shared.

Regards,

Xiaoxin Sheng

Community Support Team _ Xiaoxin
If this post helps, please consider accept as solution to help other members find it more quickly.
amitchandak
Super User
Super User

Helpful resources

Announcements
RTI Forums Carousel3

New forum boards available in Real-Time Intelligence.

Ask questions in Eventhouse and KQL, Eventstream, and Reflex.

MayPowerBICarousel1

Power BI Monthly Update - May 2024

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