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

Next up in the FabCon + SQLCon recap series: The roadmap for Microsoft SQL and Maximizing Developer experiences in Fabric. All sessions are available on-demand after the live show. Register now

Reply
Anonymous
Not applicable

Variables in Analytics Query Source

I have a query called, "Calculations" with a single record with a field ("ReportString") that holds a string that needs to be used in another query.  For example, today that string is "2023-04-20T06:00:00Z".  This cannot be obtained directly with a utcnow function because it must be 6:00:00Z, regardless of when it is called, so I piece this value together to create "ReportString".  So far, so good.

 

I have an analytics query that uses a source from "Windows Update for Business" data.  The query statement reads (in part):

 

[Query=[#"query"="let _SnapshotTime = datetime(2023-04-20T06:00:00Z);
UCClient
| where TimeGenerated == _SnapshotTime
| summarize SecurityUpdateStatus = count() by OSSecurityUpdateStatus
",#"x-ms-app"=

 

I want to replace the value in the datetime function (which is currently hard-coded) with the value from the "Calculations" query (where the value is called, "ReportString").

 

Normally, I could use "List.Min(Calculations[ReportString])" to get the value.  (Since there is only one record, List.Min gives me the first and only record).  This works great if I put it in a step after the source step... but I can't get it to work inside the source step.

 

I've tried things like:

 

[Query=[#"query"="let _SnapshotTime = datetime(List.Min(Calculations[ReportString]));
UCClient
| where TimeGenerated == _SnapshotTime
| summarize SecurityUpdateStatus = count() by OSSecurityUpdateStatus
",#"x-ms-app"=

 

...but it seems to get all hung up because it doesn't want to expand that since it's inside the quotes that start the query statement.

 

Any ideas how to attack this?

1 ACCEPTED SOLUTION
Anonymous
Not applicable

After trying multiple things, I finally ran into one that worked.

Essentially, If I declare a variable at the top:

 

let RDS = List.Min(Calculations[ReportString]),
AnalyticsQuery =

 

I can then do:

 

[Query=[#"query"= "let _SnapshotTime = datetime("&RDS&");
UCClient

View solution in original post

1 REPLY 1
Anonymous
Not applicable

After trying multiple things, I finally ran into one that worked.

Essentially, If I declare a variable at the top:

 

let RDS = List.Min(Calculations[ReportString]),
AnalyticsQuery =

 

I can then do:

 

[Query=[#"query"= "let _SnapshotTime = datetime("&RDS&");
UCClient

Helpful resources

Announcements
New to Fabric survey Carousel

New to Fabric Survey

If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.

Join our Fabric User Panel

Join our Fabric User Panel

Share feedback directly with Fabric product managers, participate in targeted research studies and influence the Fabric roadmap.

March Power BI Update Carousel

Power BI Community Update - March 2026

Check out the March 2026 Power BI update to learn about new features.