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

Earn the coveted Fabric Analytics Engineer certification. 100% off your exam for a limited time only!

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
April AMA free

Microsoft Fabric AMA Livestream

Join us Tuesday, April 09, 9:00 – 10:00 AM PST for a live, expert-led Q&A session on all things Microsoft Fabric!

March Fabric Community Update

Fabric Community Update - March 2024

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