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

Be one of the first to start using Fabric Databases. View on-demand sessions with database experts and the Microsoft product team to learn just how easy it is to get started. Watch now

Reply
Alinap00
New Member

Python Coding in custom column

Hi I'm trying to make a custom column that takes the values of another row and divides it by the number of working days left in a month. To calculate the number of working days in a month there's this code in python: import datetime # Get today's date today = datetime.date.today # Get the first day of the next month if today.month == 12: next_month = today.replace(year=today.year + 1, month=1, day=1) else: next_month = today.replace(month=today.month + 1, day=1) # Calculate the number of days left in the current month, excluding Sundays x = (next_month - today).days for i in range(x): date = today + datetime.timedelta(days=i) if date.weekday() == 6: # Sunday x -= 1 print("Value of x:", x) How do I do this in Power BI for my custom column?
1 REPLY 1
lbendlin
Super User
Super User

You cannot do that in DAX.  If you want to materialize new columns you need to run Python scripts in Power Query. Note that the Python script by defaults expects a table, and outputs a table.

Helpful resources

Announcements
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!

ArunFabCon

Microsoft Fabric Community Conference 2025

Arun Ulag shares exciting details about the Microsoft Fabric Conference 2025, which will be held in Las Vegas, NV.

December 2024

A Year in Review - December 2024

Find out what content was popular in the Fabric community during 2024.