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

Get certified in Microsoft Fabric—for free! For a limited time, get a free DP-600 exam voucher to use by the end of 2024. Register now

Reply
abaken
Regular Visitor

How to a filter A Select command

Hi

 

I have the following code in a Powerbi query.  How do I change it to select a date range ? Thank YOu 

 

Allister

 

let
Source = GetConsolidatedSQLData("Select accountcode, branchcode, departmentcode, transactiondate, transactionamount, periodno, yearno, periodid from GLTRAN Where transactiodate =31/07/22"),
#"Changed Type" = Table.TransformColumnTypes(Source,{{"AccountCode", type text}, {"BranchCode", type text}, {"DepartmentCode", type text}, {"PeriodNo", type text}, {"YearNo", type text}, {"PeriodID", type text},

 

{"CompanyCode", type text}, {"TransactionAmount", Currency.Type}, {"TransactionDate", type date}})

in
#"Changed Type"

2 REPLIES 2
abaken
Regular Visitor

Hi

 

The code for GetConsolidatedSQLData is below.

 

I want to leave this code alone if I can as it is used by several queries some of which do not require a date range filter.

 

How Can I do this ?

Thank You

 

Allister

 

let
Source = (sqlstmt as text) => let

AccData1= GetSQLData(sqlstmt,"NLD"),
AccData1c = Table.AddColumn(AccredoData1,"CompanyCode", each "NLD"),

AccData2= GetSQLData(sqlstmt,"AKL"),
AccData2c = Table.AddColumn(AccredoData2,"CompanyCode", each "AKL"),


AccData = Table.Combine({
AccData1c
,AccData2c

})
in
AccredoData
in
Source

Stachu
Community Champion
Community Champion

in the SQL you have hardcoded single date, so I assume you need to change the SQL WHERE condition. What is the definition of the GetConsolidatedSQLData measure? It can have some additional logic regarding the date too



Did I answer your question? Mark my post as a solution!
Thank you for the kudos 🙂

Helpful resources

Announcements
November Carousel

Fabric Community Update - November 2024

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

Live Sessions with Fabric DB

Be one of the first to start using Fabric Databases

Starting December 3, join live sessions with database experts and the Fabric product team to learn just how easy it is to get started.

Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount! Early Bird pricing ends December 9th.

Nov PBI Update Carousel

Power BI Monthly Update - November 2024

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