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

Microsoft is giving away 50,000 FREE Microsoft Certification exam vouchers. Get Fabric certified for FREE! Learn more

Reply
mybarbie9917_LI
Frequent Visitor

MS Fabric Notebook Spark Reading Data from Semantic Model

mybarbie9917_LI_0-1740511533916.png

I'm using Fabric notebook to read data from PBI semantic model using Spark.  The above table only has around 180k rows and but it took 45 minutes to retrieve data. 

mybarbie9917_LI_1-1740511612721.png

In the past, it didn't take that long - typically just a few minutes. I'm trying to write this data to a Lakehouse destination and it can never finish the job. This table is one of the smallest and I have other bigger tables to work on. I'm using Fabric capacity. Did MS change something last week or is there anything I can do? 

9 REPLIES 9
Pradeep_O_S
Frequent Visitor

Which Fabric SKU are you using?

v-karpurapud
Community Support
Community Support

Hello @mybarbie9917_LI 

I hope this information is helpful. Please let me know if you have any further questions or if you'd like to discuss this further. If this answers your question, please Accept it as a solution and give it a 'Kudos' so others can find it easily.

Thank you.

v-karpurapud
Community Support
Community Support

Hello @mybarbie9917_LI 

I wanted to check if you had the opportunity to review the information provided. Please feel free to contact us if you have any further questions. If my response has addressed your query, please accept it as a solution and give a 'Kudos' so other members can easily find it.

Thank you.

BIstvan
Resolver I
Resolver I

@mybarbie9917_LI  Have you tried running DAX query on Semnatic model.

 

Try the below. If you have issues on column names tweak in in wrangler.

 

from pyspark.sql import SparkSession
import sempy.fabric as fabric
import re

# Step 2: Initialize Spark Session (Required for PySpark)
spark = SparkSession.builder.appName("FabricDAXQuery").getOrCreate()

# Ensure the target database exists; create it if it doesn't.
spark.sql("CREATE DATABASE IF NOT EXISTS --- ANYTHING YOU WANT ---")

# Step 3: List available workspaces
df_workspaces = fabric.list_workspaces()

# Convert to PySpark DataFrame and display
df_spark_workspaces = spark.createDataFrame(df_workspaces)
df_spark_workspaces.show(truncate=False) # Display as a Spark DataFrame

# Step 4: List datasets in the specific workspace
workspace_name = "----- WORKSPACE NAME ----" # Change this to your workspace name
df_datasets = fabric.list_datasets(workspace=workspace_name)

# Step 5: Define Dataset and DAX Query
dataset_name = "---- SEMANTIC MODEL NAME -----" # Ensure this matches exactly
dax_string = """


INSERT HERE YOUR DAX QUERY

"""

# Step 6: Run DAX Query with Correct Argument Name
df_dax = fabric.evaluate_dax(
dataset=dataset_name,
dax_string=dax_string, # FIXED: Corrected argument name from `dax_query` to `dax_string`
workspace=workspace_name # Specify the correct workspace
)

# Convert result to PySpark DataFrame
df_spark_dax = spark.createDataFrame(df_dax)

for col_name in df_spark_dax.columns:
match = re.search(r'\[(.*?)\]', col_name)
if match:
# Extract the text within brackets and replace spaces with underscores
new_col_name = match.group(1).replace(" ", "_")
df_spark_dax = df_spark_dax.withColumnRenamed(col_name, new_col_name)

# Step 7: Save DataFrame as a Lakehouse table named 'DAX' under the 'LakeHouse_Sales_Report' database.
df_spark_dax.write.format("delta") \
.mode("overwrite") \
.saveAsTable("----DATABASE NAME ----.----TABLE NAME ----")

v-karpurapud
Community Support
Community Support

Hello @mybarbie9917_LI


Thank you @nilendraFabric  for your response!


Thank you for reaching out to the Microsoft Fabric Community. We understand you are experiencing a significant performance drop when querying a Power BI Semantic Model via Spark in Fabric.

 

This issue could be due to Fabric updates, Spark settings, or inefficient query execution. Since it worked in the past but has slowed down recently, it might be caused by Fabric capacity overload. If many users are running workloads, the capacity can be exhausted, slowing everything down.Could you please try the following methods:

 

 

  • Optimize Spark settings by adjusting executor cores, memory, and autoscaling. For better performance, try disabling autoscaling and using a fixed number of executors.

 

 

If the issue persists, it may be helpful to open a support ticket with Microsoft Fabric for further investigation.

How to create a Fabric and Power BI Support ticket - Power BI | Microsoft Learn 

 

 

If my response has resolved your query, please mark it as the Accepted Solution to assist others. Additionally, a 'Kudos' would be appreciated if you found my response helpful.

 

Thank you!

 

Hello @mybarbie9917_LI 

May I ask if you have resolved this issue? If so, please mark the helpful reply and accept it as the solution. This will be helpful for other community members who have similar problems to solve it faster.

Thank you.

nilendraFabric
Community Champion
Community Champion

Hello @mybarbie9917_LI 

 

Not sure if something changed but worth trying the query using sempy

 

from sempy.fabric import FabricDataFrame

d_person = FabricDataFrame.read_table("Semantic Model", "d_person")
d_person = d_person[(d_person.on_leave == 'No') &
(d_person.fte_cw.isin(['FTE', 'CW', 'Other']))]

 

 `FabricDataFrame` propagates Power BI metadata (relationships, hierarchies) for optimized execution

 

 

 

Hi @nilendraFabric! Thanks for your recommendation. I tried your codes but FabricDataFrame Class in Fabric doesn't have the method <FabricDataFrame.read_table>.

I also tried the regular <fabric.read_table> to read the whole table but it keeps running for 15 minutes without result.  

 

import sempy.fabric as fabric
d_person = fabric.read_table(
dataset = "Semantic Model", 
table = "d_person", 
workspace = 'Workspace'
num_rows = 100,
verbose=1)

 

 

Hello @mybarbie9917_LI 

 

Try with different modes :


df_onelake = FabricDataFrame.read_table(
dataset="YourDatasetName",
table="YourTableName",
mode='onelake',
onelake_import_method='spark'
)

Helpful resources

Announcements
MarchFBCvideo - carousel

Fabric Monthly Update - March 2025

Check out the March 2025 Fabric update to learn about new features.

March2025 Carousel

Fabric Community Update - March 2025

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

"); $(".slidesjs-pagination" ).prependTo(".pagination_sec"); $(".slidesjs-pagination" ).append("
"); $(".slidesjs-play.slidesjs-navigation").appendTo(".playpause_sec"); $(".slidesjs-stop.slidesjs-navigation").appendTo(".playpause_sec"); $(".slidesjs-pagination" ).append(""); $(".slidesjs-pagination" ).append(""); } catch(e){ } /* End: This code is added by iTalent as part of iTrack COMPL-455 */ $(".slidesjs-previous.slidesjs-navigation").attr('tabindex', '0'); $(".slidesjs-next.slidesjs-navigation").attr('tabindex', '0'); /* start: This code is added by iTalent as part of iTrack 1859082 */ $('.slidesjs-play.slidesjs-navigation').attr('id','playtitle'); $('.slidesjs-stop.slidesjs-navigation').attr('id','stoptitle'); $('.slidesjs-play.slidesjs-navigation').attr('role','tab'); $('.slidesjs-stop.slidesjs-navigation').attr('role','tab'); $('.slidesjs-play.slidesjs-navigation').attr('aria-describedby','tip1'); $('.slidesjs-stop.slidesjs-navigation').attr('aria-describedby','tip2'); /* End: This code is added by iTalent as part of iTrack 1859082 */ }); $(document).ready(function() { if($("#slides .item").length < 2 ) { /* Fixing Single Slide click issue (commented following code)*/ // $(".item").css("left","0px"); $(".item.slidesjs-slide").attr('style', 'left:0px !important'); $(".slidesjs-stop.slidesjs-navigation").trigger('click'); $(".slidesjs-previous").css("display", "none"); $(".slidesjs-next").css("display", "none"); } var items_length = $(".item.slidesjs-slide").length; $(".slidesjs-pagination-item > button").attr("aria-setsize",items_length); $(".slidesjs-next, .slidesjs-pagination-item button").attr("tabindex","-1"); $(".slidesjs-pagination-item button").attr("role", "tab"); $(".slidesjs-previous").attr("tabindex","-1"); $(".slidesjs-next").attr("aria-hidden","true"); $(".slidesjs-previous").attr("aria-hidden","true"); $(".slidesjs-next").attr("aria-label","Next"); $(".slidesjs-previous").attr("aria-label","Previous"); //$(".slidesjs-stop.slidesjs-navigation").attr("role","button"); //$(".slidesjs-play.slidesjs-navigation").attr("role","button"); $(".slidesjs-pagination").attr("role","tablist").attr("aria-busy","true"); $("li.slidesjs-pagination-item").attr("role","list"); $(".item.slidesjs-slide").attr("tabindex","-1"); $(".item.slidesjs-slide").attr("aria-label","item"); /*$(".slidesjs-stop.slidesjs-navigation").on('click', function() { var itemNumber = parseInt($('.slidesjs-pagination-item > a.active').attr('data-slidesjs-item')); $($('.item.slidesjs-slide')[itemNumber]).find('.c-call-to-action').attr('tabindex', '0'); });*/ $(".slidesjs-stop.slidesjs-navigation, .slidesjs-pagination-item > button").on('click keydown', function() { $.each($('.item.slidesjs-slide'),function(i,el){ $(el).find('.c-call-to-action').attr('tabindex', '-1'); }); var itemNumber = parseInt($('.slidesjs-pagination-item > button.active').attr('data-slidesjs-item')); $($('.item.slidesjs-slide')[itemNumber]).find('.c-call-to-action').attr('tabindex', '0'); }); $(".slidesjs-play.slidesjs-navigation").on('click', function() { $.each($('.item.slidesjs-slide'),function(i,el){ $(el).find('.c-call-to-action').attr('tabindex', '-1'); }); }); $(".slidesjs-pagination-item button").keyup(function(e){ var keyCode = e.keyCode || e.which; if (keyCode == 9) { e.preventDefault(); $(".slidesjs-stop.slidesjs-navigation").trigger('click').blur(); $("button.active").focus(); } }); $(".slidesjs-play").on("click",function (event) { if (event.handleObj.type === "click") { $(".slidesjs-stop").focus(); } else if(event.handleObj.type === "keydown"){ if (event.which === 13 && $(event.target).hasClass("slidesjs-play")) { $(".slidesjs-stop").focus(); } } }); $(".slidesjs-stop").on("click",function (event) { if (event.handleObj.type === "click") { $(".slidesjs-play").focus(); } else if(event.handleObj.type === "keydown"){ if (event.which === 13 && $(event.target).hasClass("slidesjs-stop")) { $(".slidesjs-play").focus(); } } }); $(".slidesjs-pagination-item").keydown(function(e){ switch (e.which){ case 37: //left arrow key $(".slidesjs-previous.slidesjs-navigation").trigger('click'); e.preventDefault(); break; case 39: //right arrow key $(".slidesjs-next.slidesjs-navigation").trigger('click'); e.preventDefault(); break; default: return; } $(".slidesjs-pagination-item button.active").focus(); }); }); // Start This code is added by iTalent as part of iTrack 1859082 $(document).ready(function(){ $("#tip1").attr("aria-hidden","true").addClass("hidden"); $("#tip2").attr("aria-hidden","true").addClass("hidden"); $(".slidesjs-stop.slidesjs-navigation, .slidesjs-play.slidesjs-navigation").attr('title', ''); $("a#playtitle").focus(function(){ $("#tip1").attr("aria-hidden","false").removeClass("hidden"); }); $("a#playtitle").mouseover(function(){ $("#tip1").attr("aria-hidden","false").removeClass("hidden"); }); $("a#playtitle").blur(function(){ $("#tip1").attr("aria-hidden","true").addClass("hidden"); }); $("a#playtitle").mouseleave(function(){ $("#tip1").attr("aria-hidden","true").addClass("hidden"); }); $("a#play").keydown(function(ev){ if (ev.which ==27) { $("#tip1").attr("aria-hidden","true").addClass("hidden"); ev.preventDefault(); return false; } }); $("a#stoptitle").focus(function(){ $("#tip2").attr("aria-hidden","false").removeClass("hidden"); }); $("a#stoptitle").mouseover(function(){ $("#tip2").attr("aria-hidden","false").removeClass("hidden"); }); $("a#stoptitle").blur(function(){ $("#tip2").attr("aria-hidden","true").addClass("hidden"); }); $("a#stoptitle").mouseleave(function(){ $("#tip2").attr("aria-hidden","true").addClass("hidden"); }); $("a#stoptitle").keydown(function(ev){ if (ev.which ==27) { $("#tip2").attr("aria-hidden","true").addClass("hidden"); ev.preventDefault(); return false; } }); }); // End This code is added by iTalent as part of iTrack 1859082
Top Solution Authors
Top Kudoed Authors
Users online (1,599)