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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
Anonymous
Not applicable

Dynamic data importing from a database using Native Database Query (Power Query)

Hello everyone ,

 

I have an question I import data using Native Database Query (Power Query) for particular Year 2024 , is there a way how to make Pwer Quary dynamic? If so, what would I need to do so?  The "EventDate" values??

 

 I have it for 2024 but I would like if a user would be able to change Year 2023 or 2022 and so on.... 

 

 

3 REPLIES 3
rajendraongole1
Super User
Super User

Hi @Anonymous - Open Power BI Desktop and go to Power Query Editor.
In the Home tab, select Manage Parameters > New Parameter.
Name the parameter, for example, YearParameter.
Set the Type to Whole Number and provide a Current Value (e.g., 2024). This value will act as the default.
Optionally, you can provide a list of possible years that users can choose from (e.g., 2022, 2023, 2024, etc.)

You can try the below parameter in select:

 

SELECT cec_0.[CecCaseId], cec_0.[CaseId],
(SELECT CAST(CASE WHEN EXISTS (SELECT * FROM CecRepetitiveCase WHERE LeadingCecCaseId = cec_0.CaseID) THEN 1 ELSE 0 END AS BIT)) AS [HasClones],
cec_1.[RegisteredNo], cec_1.[Stateid],
cec_2.[StateOfProceedingName]
FROM [dbo].[CecCaseDetail] (nolock) AS cec_0
INNER JOIN [dbo].[CaseDetail] (nolock) AS cec_1
ON cec_1.CaseID = cec_0.CaseId
INNER JOIN [dbo].[CecStateOfProceeding] (nolock) AS cec_2
ON cec_2.StateOfProceedingID = cec_0.StateOfProceedingID
LEFT JOIN [dbo].[DGIIAgent] (nolock) AS cec_5
ON cec_5.AgentID = cec_0.PrincipalAgentID
WHERE EXISTS (SELECT * FROM [dbo].[CecCaseEvent] zz
WHERE zz.CecCaseID = cec_0.CecCaseID
AND zz.EventID = 1
AND zz.EventDate >= CONVERT(DATETIME, '01/01/" & Text.From(YearParameter) & " 00:00:00', 103))
AND EXISTS (SELECT * FROM CecLeadingCase zz WHERE zz.CecCaseId = cec_0.CecCaseId)
AND cec_0.StateOfProceedingID IN (2)
AND cec_1.RegisteredNo <> '0'
ORDER BY cec_1.RegisteredNo

 





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!





Anonymous
Not applicable

Hello Rajendraongole1,

 

Thank you for respone, where to put your amended code??  I tried to implemented your solution, but how it works now... I would like a user change year.. visually. 

Anonymous
Not applicable

Thanks for the reply from rajendraongole1 , please allow me to provide another insight:

Hi, @Anonymous 
 

Based on my understanding, the solution that rajendraongole1  is suggesting is set up as follows:

1.Firstly, modify the parameters in Power Query. Here is my reference example:

vlinyulumsft_1-1730101485120.png

2.Secondly, click on Advanced Editor to modify the M language. My example is as follows:

vlinyulumsft_2-1730101485122.png

As we cannot directly access the data source, you will need to adjust the specific code according to your particular circumstances.

vlinyulumsft_3-1730101570415.png

 

Best Regards,

Leroy Lu

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

December 2025 Power BI Update Carousel

Power BI Monthly Update - December 2025

Check out the December 2025 Power BI Holiday Recap!

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.