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

Get Fabric Certified for FREE during Fabric Data Days. Don't miss your chance! Request now

Reply
POWER_MI
Post Patron
Post Patron

script or SQL request to select data of filter's

Hi all, 

Have some question about Power BI. 

 

The asking is to selection some data based on some criteria that we fixe when we import excel file to power BI, i explain :

 

For example if you have Table coluumn like 

 

project A         Data Project A     Data Project A-1    Data Project A-2

.....                    ......

When you will import excel file on power  Bi you will need to select just the data need for example 

If project A = Value p1  and Data Project A= Value DP1 and Data Project A-1=DP1-1

So how to implemente this condition when we import excel on power BI may be with script R ou SQL sript and how to do it automatiquily without any action from user ?

 

thanks for help

 

1 ACCEPTED SOLUTION

Hi @POWER_MI 

 

Please try the following codes, the key codes are #"Filtered Rows" step.

let
    Source = Excel.Workbook(File.Contents("C:\Users\xxxx\Desktop\ExcelData.xlsx"), null, true),
    Sheet1_Sheet = Source{[Item="Sheet1",Kind="Sheet"]}[Data],
    #"Changed Type" = Table.TransformColumnTypes(Sheet1_Sheet,{{"Column1", type text}, {"Column2", type text}, {"Column3", type text}}),
    #"Promoted Headers" = Table.PromoteHeaders(#"Changed Type", [PromoteAllScalars=true]),
    #"Changed Type1" = Table.TransformColumnTypes(#"Promoted Headers",{{"Project", type text}, {"Step", type text}, {"Code", type text}}),
    #"Filtered Rows" = Table.SelectRows(#"Changed Type1", each (([Project] = "AAVy_ii" and [Step] = "Y1" and [Code] = "Co1" )) or ([Project] = "AAVy_2" and [Step] = "Y3") or ([Project] = "AAVy_3" and [Step] = "Y1"))
in
    #"Filtered Rows"

121501.jpg

 

Kindly let me know if this helps.

Community Support Team _ Jing Zhang
If this post helps, please consider Accept it as the solution to help other members find it.

View solution in original post

6 REPLIES 6
POWER_MI
Post Patron
Post Patron

script on Power Query like 

let
Source = Excel.Workbook(File.Contents(....

if ..

 

Hi @POWER_MI 

 

Please try the following codes, the key codes are #"Filtered Rows" step.

let
    Source = Excel.Workbook(File.Contents("C:\Users\xxxx\Desktop\ExcelData.xlsx"), null, true),
    Sheet1_Sheet = Source{[Item="Sheet1",Kind="Sheet"]}[Data],
    #"Changed Type" = Table.TransformColumnTypes(Sheet1_Sheet,{{"Column1", type text}, {"Column2", type text}, {"Column3", type text}}),
    #"Promoted Headers" = Table.PromoteHeaders(#"Changed Type", [PromoteAllScalars=true]),
    #"Changed Type1" = Table.TransformColumnTypes(#"Promoted Headers",{{"Project", type text}, {"Step", type text}, {"Code", type text}}),
    #"Filtered Rows" = Table.SelectRows(#"Changed Type1", each (([Project] = "AAVy_ii" and [Step] = "Y1" and [Code] = "Co1" )) or ([Project] = "AAVy_2" and [Step] = "Y3") or ([Project] = "AAVy_3" and [Step] = "Y1"))
in
    #"Filtered Rows"

121501.jpg

 

Kindly let me know if this helps.

Community Support Team _ Jing Zhang
If this post helps, please consider Accept it as the solution to help other members find it.

POWER_MI
Post Patron
Post Patron

the DB excel is on enclosed screenCapture.PNG

POWER_MI
Post Patron
Post Patron

Hi all,  thanks for answer. Is it possible to make example for excel file like data base:

the condition is 

If project ID = AAVy_ii  then take Value when Step =Y1 and Co=1

If project ID = AAVy_2  then take Value when Step =Y3 

If project ID = AAVy_3  then take Value when Step =Y1

PhilipTreacy
Super User
Super User

Hi @POWER_MI 

You do this with Power Query.  When you import data you use PQ to edit and transform the data into just the subset that you want.

Even if that is a SQL database, PQ only requests the data you will need.  When you do the initial connection and preview the data it looks like it is pulling a lot more data thna you need but when the query is finished,PQ does what's called query folding and basically wites its own SQL that the database server runs to only transfer the data you want.

Further reading

https://docs.microsoft.com/en-us/power-query/power-query-what-is-power-query

https://exceleratorbi.com.au/what-is-power-query/

https://www.myonlinetraininghub.com/excel-power-query-course

https://exceleratorbi.com.au/how-query-folding-works/

Regards

Phil


If I answered your question please mark my post as the solution.
If my answer helped solve your problem, give it a kudos by clicking on the Thumbs Up.



Did I answer your question? Then please mark my post as the solution.
If I helped you, click on the Thumbs Up to give Kudos.


Blog :: YouTube Channel :: Connect on Linkedin


Proud to be a Super User!


amitchandak
Super User
Super User

@POWER_MI , if it is a databse, in connection you write SQL of your choice

AdvanceProperty.png

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

Helpful resources

Announcements
Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

October Power BI Update Carousel

Power BI Monthly Update - October 2025

Check out the October 2025 Power BI update to learn about new features.

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.

Top Solution Authors
Top Kudoed Authors