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

Earn a 50% discount on the DP-600 certification exam by completing the Fabric 30 Days to Learn It challenge.

Reply
dbraverman
Frequent Visitor

Current file name in Power BI report

I am struggling to get the current file name in the Power BI report.
I tried the following solutions:

FileName =

VAR FilePath = LEFT(PATH(), FIND("[", PATH(), 1) - 2)

RETURN

RIGHT(FilePath, LEN(FilePath) - FIND("\", REVERSESTRING(FilePath), 1))

 

let

    Source = #shared,

    CurrentWorkbook = Source{[Name="CurrentWorkbook"]}[Content],

    FileName = CurrentWorkbook{[Name="Name"]}[Content]

in

    Filename

 

let

    Source = #table({"FileName"}, {{Uri.LocalFileFromPath(#shared[Content])}})

in

    Source

 

FileName = FIRSTNONBLANK(FileNameQuery[FileName], 1)

 

Current File Name = VALUE.NATIVEQUERYMETADATA()[Source.Name]

 

Current File Name Without Extension =

    REPLACELASTSTRING(

        VALUE.NATIVEQUERYMETADATA()[Source.Name],

        ".pbix", ""

    )

 

  1.             In Power Query, create a new blank query
  2.             Enter = [Source. Name] to create a column with the file name
  3.             Remove any other columns
  4.             Right-click the query and select "Reference" to load it into the model
  5.             In DAX, reference this table, e.g. = 'Query Name'[Source. Name]

None of them are working. Any ideas?

3 REPLIES 3
dbraverman
Frequent Visitor

Thanks for that but this is not what I need. I am not interested in external file names. I need to get the current pbix file name using DAX or M.

Hi @dbraverman 

Thanks for your quirck reply, if you want to get the current pbix file, it is not support in power bi desktop, you can refer to the followign link.

Get the name of .pbix file - Microsoft Fabric Community

 

Best Regards!

Yolo Zhu

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

 

v-xinruzhu-msft
Community Support
Community Support

Hi @dbraverman 

You can consider try the following solution.

You can put your file to a folder, then use get data from a folder.

e.g Now I have an excel file, then put it into a folder named new folder.

1.Select get data from folder.

vxinruzhumsft_0-1715570100645.png

2.Select the folder.

vxinruzhumsft_1-1715570175154.png

 

3.Transform the data 

vxinruzhumsft_2-1715570200489.png

4.In this case, it has the "~" in Name column, need to filter out  the name that contains"~"

vxinruzhumsft_0-1715576843582.png

5.In power query select the content and name column, then select remove other columns.

vxinruzhumsft_3-1715570241832.png

6.Then select combine the content.

vxinruzhumsft_4-1715570302192.png

7.After combine, click the following step. and remove the other steps below this step.

vxinruzhumsft_5-1715570486916.png

8.Then remove the content column, then extend the transform file column.

vxinruzhumsft_6-1715570554883.png

Then name will keep 

Output

vxinruzhumsft_7-1715570580675.png

And you can refer to the following advanced code.

 

 

let
    Source = Folder.Files("xxx"),//your file path
    #"Removed Other Columns" = Table.SelectColumns(Source,{"Name", "Content"}),
    #"Filtered Hidden Files1" = Table.SelectRows(#"Removed Other Columns", each [Attributes]?[Hidden]? <> true),
    #"Filtered Rows" = Table.SelectRows(#"Filtered Hidden Files1", each not Text.Contains([Name], "~")),
    #"Filtered Hidden Files2" = Table.SelectRows(#"Filtered Rows", each [Attributes]?[Hidden]? <> true),
    #"Invoke Custom Function1" = Table.AddColumn(#"Filtered Hidden Files2", "Transform File", each #"Transform File"([Content])),
    #"Removed Columns" = Table.RemoveColumns(#"Invoke Custom Function1",{"Content"})
in
 #"Removed Columns"

 

 

And you can refer to the followng link.

Solved: adding the file name to a column in power query - Microsoft Fabric Community

 

Best Regards!

Yolo Zhu

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

Helpful resources

Announcements
LearnSurvey

Fabric certifications survey

Certification feedback opportunity for the community.

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

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

April Fabric Community Update

Fabric Community Update - April 2024

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