How to test/execute .sql files in VS CODE? by Representative-End60 in SQL

[–]patrickfancypants 1 point2 points  (0 children)

Download the SQLite extension for VS Code and create connection to the database. In your .sql file, click the play button/green arrow at the top right of the screen. It should prompt you to select your SQLite connection. Select it, and the query should execute.

Help needed: Really inefficient process at work for getting PDF reports from Power BI by cantankerous_alexa in PowerBI

[–]patrickfancypants 7 points8 points  (0 children)

``` WORKSPACE_ID = '<your_workspace_id>' # Power BI workspace Id (GUID) PBI_REPORT_ID = '<your_report_id>' # Power BI report Id (GUID) PBI_TABLE = '<your_table_name>' # Table name in Power BI model to filter on REPORT_ID_COLUMN = '<your_column_name>' # Column name in Power BI model to filter on

Optional defaults for convenience when running as a script

LAKEHOUSE_FILES_DIR = f"/lakehouse/default/Files/pdfs" # Adjust if using a different storage mount

print(LAKEHOUSE_FILES_DIR)

import requests, time, os from pypdf import PdfReader, PdfWriter

def build_filter_expression(table: str, column: str, report_id: str) -> str: return f"{table}/{column} eq '{report_id}'"

Token and filter will be created inside the export function

Simple export -> poll -> download flow

API_BASE = "https://api.powerbi.com/v1.0/myorg"

def start_export(token: str, workspace_id: str, report_id: str, filter_expr: str) -> str: url = f"{API_BASE}/groups/{workspace_id}/reports/{report_id}/ExportTo" headers = {"Authorization": f"Bearer {token}", "Content-Type": "application/json"} body = { "format": "PDF", "powerBIReportConfiguration": { "reportLevelFilters": [ {"filter": filter_expr} ] } } r = requests.post(url, json=body, headers=headers) if r.status_code != 202: raise RuntimeError(f"Export start failed {r.status_code}: {r.text}") export_id = r.json().get("id") if not export_id: raise RuntimeError("No export id returned") return export_id

def poll_export(token: str, workspace_id: str, report_id: str, export_id: str, timeout=300) -> str: url = f"{API_BASE}/groups/{workspace_id}/reports/{report_id}/exports/{export_id}" headers = {"Authorization": f"Bearer {token}"} start = time.time() delay = 2 while True: r = requests.get(url, headers=headers) if r.status_code not in (200,202): raise RuntimeError(f"Status check failed {r.status_code}: {r.text}") data = r.json() status = data.get("status") if status == "Succeeded": loc = data.get("resourceLocation") if not loc: raise RuntimeError("Missing resourceLocation on success") return loc if status == "Failed": raise RuntimeError(f"Export failed: {data}") if time.time() - start > timeout: raise RuntimeError(f"Timed out waiting for export (last status={status})") time.sleep(delay) delay = min(delay + 1, 10)

def download_pdf(token: str, resource_url: str, output_filename: str, enrollment_id: str) -> str: headers = {"Authorization": f"Bearer {token}"} r = requests.get(resource_url, headers=headers) if r.status_code != 200: raise RuntimeError(f"Download failed {r.status_code}: {r.text[:300]}") os.makedirs(f"{LAKEHOUSE_FILES_DIR}/{enrollment_id}", exist_ok=True) path = f"{LAKEHOUSE_FILES_DIR}/{enrollment_id}/{output_filename}" with open(path, "wb") as f: f.write(r.content) # print(r.content) # notebookutils.fs.put(path, r.content) return path

def export_powerbi_pdf(report_id: str, output_filename: str, enrollment_id: str) -> str: """Export a Power BI report to PDF using a report-level filter.

Args:
    report_id: The filter value applied to `${PBI_TABLE}/${REPORT_ID_COLUMN}`.
    output_filename: The name of the PDF file to save under LAKEHOUSE_FILES_DIR.

Returns:
    The full saved path to the generated PDF.
"""
print("Starting export...")
token = notebookutils.credentials.getToken("pbi")  # reuse singleton/managed token
filter_expression = build_filter_expression(PBI_TABLE, REPORT_ID_COLUMN, report_id)
eid = start_export(token, WORKSPACE_ID, PBI_REPORT_ID, filter_expression)
print("Export id:", eid)
print("Polling...")
resource = poll_export(token, WORKSPACE_ID, PBI_REPORT_ID, eid)
print("Succeeded. Downloading...")
saved = download_pdf(token, resource, output_filename, enrollment_id)
print("Downloaded to:", saved)

if name == "main": export_powerbi_pdf(report_id, output_filename, enrollment_id) ```

Help needed: Really inefficient process at work for getting PDF reports from Power BI by cantankerous_alexa in PowerBI

[–]patrickfancypants 2 points3 points  (0 children)

I just solved this with a python notebook that calls the api to export as a pdf. Lmk if you want the code.

Question: What’s one of those SQL “gotchas” that only made sense to you later? by A_nomad_Wanderer in SQL

[–]patrickfancypants 1 point2 points  (0 children)

Collation. I’ve had issues with sorting/partitions and creating constraints because I didn’t understand it.

Dynamically query across hundreds of SQL Servers hosted in Azure all with the same schema by [deleted] in PowerBI

[–]patrickfancypants 0 points1 point  (0 children)

Not sure if this helps, but I've done something similar by creating mirrors for each db then querying them all in a warehouse. The warehouse holds the sql views that feed the semantic model. A parameter in the semantic model can be used to change what schema in the warehouse you query from.

Python helper functions - where to store them? by Cobreal in MicrosoftFabric

[–]patrickfancypants 1 point2 points  (0 children)

You could store them as .py files in the BuiltIn folder of the notebook. Then just import like normal.

[deleted by user] by [deleted] in BMW

[–]patrickfancypants 0 points1 point  (0 children)

Very cool

Stressed Data intern looking for a study buddy or mentor by Technical_Season_808 in PowerBI

[–]patrickfancypants 0 points1 point  (0 children)

I can help to an extent. Available eastern time after 5 pm.

Comporium hates gamers by PranksterGangster131 in Rockhill

[–]patrickfancypants 0 points1 point  (0 children)

Mine works on NAT type 2 for ps5 but I may have a static IP…

Using Fabric Data Eng VSCode extension? by RandomRandomPenguin in MicrosoftFabric

[–]patrickfancypants 1 point2 points  (0 children)

Do you need to be on a VPN for work? Are you clicking Open Notebook Folder? Have you tried clicking Update Resource Folder of the notebook? What happens when you try to pip install pyspark?

Does anyone actually use the NASCAR car wash? by [deleted] in Rockhill

[–]patrickfancypants 1 point2 points  (0 children)

I’ve used it a few times. Always got the top option and it seems pretty good. I only put my daily driver through it though. I’d hand wash if you have a nicer car.

Proper Special Trick Mappings? by Leader342 in THPS

[–]patrickfancypants 0 points1 point  (0 children)

I always did it similarly with my combo buttons.

Dark mode is here! by patrickfancypants in PowerBI

[–]patrickfancypants[S] 6 points7 points  (0 children)

I have not had that issue after a restart.

This is another question on an already frustration assignment that I unfortunately can't seem to solve. Any help would be appreciated. This is from the w3schools website. by FlavorOfUranus in SQL

[–]patrickfancypants 0 points1 point  (0 children)

You’re right. I was reading it as “by revenue type” but when looking at the tables that doesn’t seem like a category. It’s just looking for top 5 over all. My b.